Jump to content

Page Rename Options


adrian

Recommended Posts

@adrian When you get back online please fix the below issue:

Problem: Removing the title from an additional language the page name doesn't switch back to default's language name.
Solution: You have to remove this update. You added that cause @videokid had problem with the Greek characters. If someone wants to replace non-latin characters there is a module on PW Core modules called "Page Name".  There you can add for example the Greek characters to convert to latin characters. Like this: α=a

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hi @PWaddict - thanks for the report and for finding the solution - much appreciated. I have removed the changes from that update (I agree that the Page Name core module should be used to define those replacements).

I noticed in the original version of your last post you mentioned a second more critical bug, but you've now deleted that - can you please confirm that everything is in fact OK with that and that nothing needs fixing?

  • Like 1
Link to comment
Share on other sites

Hi @adrian and welcome back :)

Thanks for the fix on the first problem. Now about the 2nd problem, I deleted that cause I wanted to do more testing. So here is the full problem...

Problem (1st part): If I add a title on an additional language field eg. "Test" where that exact title "Test" is already on another page's additional language field from the same template when I save the page the title disappears and I'm getting the error: Session: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'test-1018' for key 'name1977_parent_id'.

Problem (2nd part): If I add a title on the default language field eg. "Test" where that exact title "Test" is already on another page's default language field from the same template the page saved as /test-1 for all languages which is correct BUT if on that page (/test-1) add the same title "Test" on an additional language field the page name for that language will be saved as /test which is wrong cause now I have 2 pages with the same page names.

Solution: Page name for additional language should be checked if already exists and name it properly just like it happens on the default language: Session: Changed page URL name to "test-1" because requested name was already taken.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 7/4/2017 at 10:32 PM, PWaddict said:

Hi @adrian and welcome back :)

Thanks for the fix on the first problem. Now about the 2nd problem, I deleted that cause I wanted to do more testing. So here is the full problem...

Problem (1st part): If I add a title on an additional language field eg. "Test" where that exact title "Test" is already on another page's additional language field from the same template when I save the page the title disappears and I'm getting the error: Session: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'test-1018' for key 'name1977_parent_id'.

Problem (2nd part): If I add a title on the default language field eg. "Test" where that exact title "Test" is already on another page's default language field from the same template the page saved as /test-1 for all languages which is correct BUT if on that page (/test-1) add the same title "Test" on an additional language field the page name for that language will be saved as /test which is wrong cause now I have 2 pages with the same page names.

Solution: Page name for additional language should be checked if already exists and name it properly just like it happens on the default language: Session: Changed page URL name to "test-1" because requested name was already taken.

Just looking at this now and it actually looks like this is the same behaviour as the PW core. Try disabling this module and manually change an additional language "name" for a page. Sometimes I get the integrity constraint violation and other times it actually names the page the same without an error and without adding a "-1". Can you please confirm the same behaviour at your end and if so, maybe this should be fixed in the core instead.

  • Like 1
Link to comment
Share on other sites

34 minutes ago, adrian said:

Just looking at this now and it actually looks like this is the same behaviour as the PW core. Try disabling this module and manually change an additional language "name" for a page. Sometimes I get the integrity constraint violation and other times it actually names the page the same without an error and without adding a "-1". Can you please confirm the same behaviour at your end and if so, maybe this should be fixed in the core instead.

You're right. Both parts of the problem are caused by the core. Can you please forward it to @ryan so maybe he can fix it on the next dev release?

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Hi @adrian,

I found that the "Enable for API" option prevents Repeater pages being added via the API (for repeaters that contain a title field at least). At this point...

$r = $page->my_repeater->getNew();

...I get the error:

Quote

Exception: You may not modify 'name' on page '/processwire/repeaters/for-field-122/for-page-1349/' because it is a system page (in D:\Websites\__www\1testing\wire\core\Page.php line 716)

 

  • Like 1
Link to comment
Share on other sites

Hi @Robin S - I just tested creating a repeater item here via the API and didn't have any problems.

Any tips on how I might be able to reproduce this? Maybe send me an export of your repeater field, and an export of your PageRenameOptions settings (ModuleSettingsImportExport makes this easy) in case there is some other setting that is also involved.

 

Link to comment
Share on other sites

I just reproduced this on a clean installation.

The repeater has only the title field added and all other settings are the default.
Repeater field export:

Spoiler



{
    "test_repeater": {
        "id": 101,
        "type": "FieldtypeRepeater",
        "flags": 0,
        "name": "test_repeater",
        "label": "Test repeater",
        "template_id": 47,
        "parent_id": 1056,
        "repeaterFields": "",
        "repeaterCollapse": 0,
        "repeaterLoading": 1,
        "collapsed": 0,
        "repeaterTitle": "",
        "repeaterAddLabel": "",
        "rememberOpen": "",
        "accordionMode": "",
        "repeaterMaxItems": "",
        "repeaterMinItems": "",
        "repeaterDepth": "",
        "showIf": "",
        "columnWidth": 100,
        "required": "",
        "requiredIf": ""
    }
}


 

PageRenameOptions settings:

Spoiler



{"PageRenameOptions":{"version":"1.0.1","settings":{"enableForApi":1,"renameMatchTitle":1,"renameWithoutTitleChange":"","renameUnpublishedOnly":"","includeExclude":"exclude","exemptTemplates":[],"exemptPages":[],"exemptRoles":["superuser"],"initialDifference":1,"preventManualChanges":1,"liveChanges":null}}}


 

API code:

$p = $pages(1029); // a page that has the repeater in its template
$p->of(false);
$r = $p->test_repeater->getNew();
$r->title = "Repeater item";
$r->save();
$p->test_repeater->add($r);
$p->save();

 

Link to comment
Share on other sites

Hey @Robin S - I am using your code and module settings. The one thing I did notice when I imported your module settings though is that you are using an older version and I have a feeling that might be the reason. Please try updating to 1.0.2 and let me know.

Link to comment
Share on other sites

Just now, Robin S said:

I just installed the module brand new today. The latest version in the directory is 1.0.1.

Sorry, of course you're correct - I have a local version with some minor changes, but nothing that would affect what you are seeing.

I am not sure where to go from here - I have tried with your module settings and repeater field settings and not getting any errors and repeater items are being created just fine.

The only thing I can think of is that my test site is multi-language, but I would think that would be more complicated, not less :)

Any chance you could help debug where and why it is trying to change the name of the repeater - I don't think it should be doing that at all and I am certainly not seeing it here.

Link to comment
Share on other sites

Have narrowed down when the issue occurs. There are two conditions needed to observe the problem:

1. A page using a template containing a repeater is created via the API and is never edited and saved in admin. This means that the parent page of the repeater items under Admin > Repeaters > repeater_field is not yet created.

2. A new repeater item is added via the API to the page created in step 1. When the parent page is created to hold the repeater item, Page Rename Options attempts to rename the parent page but this is not allowed because the parent uses a system template.

The existing test for system templates in Page Rename Options fails because the page ID is 0 at this point. The fix goes here, changing a check for $p->id to $p->template:

// $p->template check is because it is not available for ProcessPageAdd
if($p->template && $p->template->flags & Template::flagSystem) return false; // exclude system templates eg. users etc

 

  • Like 1
Link to comment
Share on other sites

  • 5 months later...
2 hours ago, PWaddict said:

@adrian I noticed that if a non-superuser change the title of an additional language that page name will not be renamed.

Any chance you are running the RestrictTabView module as well? It looks like there is a conflict. I'll see if I can fix that, but it would be good to know if that's your issue as well.

Link to comment
Share on other sites

3 minutes ago, adrian said:

Any chance you are running the RestrictTabView module as well? It looks like there is a conflict. I'll see if I can fix that, but it would be good to know if that's your issue as well.

Yes, I'm running RestrictTabView too.

  • Like 1
Link to comment
Share on other sites

Please try this version of RestrictTabView. It puts the name fields onto the Content tab the PW core way, rather than hacking them hidden. I am out of time right now so not sure if this is really a friendly solution, but I think it's the only robust one when working with ML sites without a lot more work.

Anyway, let me know how it goes.

Thanks!

 

RestrictTabView.module

Link to comment
Share on other sites

On 4/7/2018 at 5:20 AM, adrian said:

Please try this version of RestrictTabView. It puts the name fields onto the Content tab the PW core way, rather than hacking them hidden. I am out of time right now so not sure if this is really a friendly solution, but I think it's the only robust one when working with ML sites without a lot more work.

Anyway, let me know how it goes.

Thanks!

 

RestrictTabView.module

Thanks for trying to fix this but I'm thinking to uninstall the module and just hide the Settings tab with CSS.

Link to comment
Share on other sites

13 hours ago, PWaddict said:

Thanks for trying to fix this but I'm thinking to uninstall the module and just hide the Settings tab with CSS.

What about this solution. It adds the name field to the Content tab, but collapses it. That way it's still available to the user if they need it, but you can still control the renaming options (including manual editing) with PageRenameOptions.

 

RestrictTabView.module

Link to comment
Share on other sites

15 hours ago, adrian said:

What about this solution. It adds the name field to the Content tab, but collapses it. That way it's still available to the user if they need it, but you can still control the renaming options (including manual editing) with PageRenameOptions.

 

RestrictTabView.module

I've already switched to the CSS solution but yeah sounds good about what you did. You should officially update the module.

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Slight bug report - if you have a template where the title is locked, it will cause the name field to clear and then you will get an error when trying to save the page about missing required value of name...

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...