joe_g Posted November 24, 2023 Share Posted November 24, 2023 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 More sharing options...
da² Posted November 24, 2023 Share Posted November 24, 2023 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); 1 Link to comment Share on other sites More sharing options...
joe_g Posted November 27, 2023 Author Share Posted November 27, 2023 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... Link to comment Share on other sites More sharing options...
da² Posted November 27, 2023 Share Posted November 27, 2023 @joe_g I thought it was easy to solve with a hook, but there's something strange: I create a page named "test" without unique status, I add a hook that set next pages as unique, I create another page "test" in a different parent, Page is saved without problem with "unique" flag and name "test", even is another page in another parent uses this name, 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 More sharing options...
da² Posted November 28, 2023 Share Posted November 28, 2023 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... Link to comment Share on other sites More sharing options...
joe_g Posted December 26, 2023 Author Share Posted December 26, 2023 Yes, thank you. I think this is what I'll do (my own check) - it feels safer. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now