Jump to content

Globally unique page name on save


joe_g
 Share

Recommended Posts

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

Link to comment
Share on other sites

@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);
});

 

Link to comment
Share on other sites

  • 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
 Share

  • Recently Browsing   0 members

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