cb2004 Posted January 21, 2019 Share Posted January 21, 2019 I am coming up against a bug where I cant make use of the functionality 'Name format for children', and it doesn't seem like a hook is possible to save the name: $wire->addHookBefore('Pages::setupNew', function(HookEvent $e) { $page = $e->arguments(0); if($this->input->parent_id === '1') { $page->name = 'some-name'; } }); I have tried many solutions from the forums, nothing is achieving what I would like, even for example if I am trying it on the home page like the code above. Any help would be much appreciated. Link to comment Share on other sites More sharing options...
Robin S Posted January 22, 2019 Share Posted January 22, 2019 Try this... $wire->addHookBefore('ProcessPageAdd::execute', function(HookEvent $event) { // Get the id of the parent page the new page is being added under $parent_id = $event->input->get->int('parent_id'); // Return early if not the id of the parent page you want to target if($parent_id !== 1234) return; // The following line probably not strictly necessary because we will redirect in a moment anyway $event->replace = true; // Create the page $p = $event->pages->add('your-template-name', $parent_id, 'your-page-name'); // Make the page unpublished to begin with $p->addStatus(Page::statusUnpublished); // Save the unpublished status $p->save(); // Redirect to edit the page just created $event->session->redirect($p->editUrl); }); 7 Link to comment Share on other sites More sharing options...
cb2004 Posted January 22, 2019 Author Share Posted January 22, 2019 8 hours ago, Robin S said: Try this... $wire->addHookBefore('ProcessPageAdd::execute', function(HookEvent $event) { // Get the id of the parent page the new page is being added under $parent_id = $event->input->get->int('parent_id'); // Return early if not the id of the parent page you want to target if($parent_id !== 1234) return; // The following line probably not strictly necessary because we will redirect in a moment anyway $event->replace = true; // Create the page $p = $event->pages->add('your-template-name', $parent_id, 'your-page-name'); // Make the page unpublished to begin with $p->addStatus(Page::statusUnpublished); // Save the unpublished status $p->save(); // Redirect to edit the page just created $event->session->redirect($p->editUrl); }); Perfect, thanks so much Robin. 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