Jump to content

Recommended Posts

Posted

Hi all,

I have a memory I've seen a module for this but I can't find it now: That when you save a page the name is globally unique, instead of just unique within it's siblings.

So that if there is another "page-with-name" somewhere my new page becomes "page-with-name-1" even though it doesn't have the same parent.

many thanks,

J

Posted

Hello @joe_g,

I see there is a "unique" property in page settings ("Settings" tab > Status), that ensures no other page will use the same name.

If you create the page with API, I think this should work:

$page->addStatus(Page::statusUnique);

 

  • Like 1
Posted

Yes thank you, but the page needs to be created the regular way (backend editing).

I found the setting, interesting! Now I just have to figure out to make this default checked for certain templates...

Posted

@joe_g

I thought it was easy to solve with a hook, but there's something strange:

  1. I create a page named "test" without unique status,
  2. I add a hook that set next pages as unique,
  3. I create another page "test" in a different parent,
  4. Page is saved without problem with "unique" flag and name "test", even is another page in another parent uses this name,
  5. If I remove the hook and try to do the same by manually checking the box: PW denies because another page uses this name.

So setting "unique" via a hook doesn't trigger the unique check when saving page, maybe @ryan can help.

I used this hook so unique flag is set before saveReady:

$this->addHookBefore('ProcessPageEdit::buildForm', function (HookEvent $event): void {
    /** @var Page $page */
    $page = $event->object->getPage();

    if ($page->template->name == 'hotlap')
        $page->addStatus(Page::statusUnique);
});

 

Posted

But you can still do your own check in this hook, searching another page with same name before to apply unique flag. Then if you find one you can throw an error, or unpublish the page or set another name...

  • 4 weeks later...

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...