Can Posted February 11, 2017 Share Posted February 11, 2017 Hola amigos, I'm trying hard to auto generate page names for certain templates no matter if they're created using admin ui or api tried various hooks I hacked myself and copied stuff from and kixes module module I tried the following in site/init.php $wire->addHookBefore('Pages::setupNew', function(HookEvent $event) { $page = $event->arguments[0]; // if($page->is('comment')) { $page->name = 'the-page-name-you-want'; // } }); $wire->addHookBefore('Pages::setupPageName', function(HookEvent $event) { $page = $event->arguments[0]; // tried with and without template check if ($page->is('comment')) { $event->replace = true; $name = 'autoname'; $event->return = $name; } }); the second hook, if i get it right, might only fire via api if no name is provided (right?) for the setupNew hook Ryan mentions "if the page doesn't have a name yet" but it seemed to work for netcarver.. what am I missing here? And in this case I want to bypass the name form completely (I already stripped the title field on this template).. UPDATE: so ___setupNew seems to work but wont bypass the page name form..so I have to provide a name, hit save and then on the page edit screen it changed to the one form the hook...how can I go straight to page edit screen after clicking on new page like when a name format is entered for children ProcessPageAdd::processQuickAdd? Link to comment Share on other sites More sharing options...
Robin S Posted February 11, 2017 Share Posted February 11, 2017 5 hours ago, Can said: And in this case I want to bypass the name form completely On the parent page template, if you select a single allowed template for children and specify a "Name format for children" then the first step of the "Add New" page process should be skipped. To set the name the core name format setting might be sufficient, or you have more options with kixe's module, or you can use your own hook: $this->pages->addHookBefore('setupNew', function($event) { $page = $event->arguments('page'); if($page->template == 'my_template') { $page->name = 'some-name'; } }); 3 Link to comment Share on other sites More sharing options...
Can Posted February 11, 2017 Author Share Posted February 11, 2017 ookay..just entered title in name format for children and modify it from the setupNew hook thanks to you @Robin S 1 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