Zeka Posted June 3, 2016 Posted June 3, 2016 Hi. Since PW 3.0.9 we have new save actions. I need to change redirect url for "Save + Exit" action. I use this code and it works great, but it works both for "Save" and "Save + Exit" buttons. $pages->addHookAfter('saved', function($event) { $page = $event->object; $page = $event->arguments(0); if($page->template == 'blog-entry') { $goto = wire("pages")->get(3062)->url; wire("session")->redirect($goto); } }); Is there way to hook only save + exit action?
LostKobrakai Posted June 3, 2016 Posted June 3, 2016 You're not hooking anything related to those buttons. This one would even execute if anything on the frontend would save a blog-entry. I'd suggest taking a look at the hooks provided by ProcessPageEdit.
Zeka Posted June 4, 2016 Author Posted June 4, 2016 You're not hooking anything related to those buttons. This one would even execute if anything on the frontend would save a blog-entry. I'd suggest taking a look at the hooks provided by ProcessPageEdit. Hi, LostKobrakai and thanks for point me in the right direction. Now i use this code. wire()->addHookBefore("ProcessPageEdit::processSaveRedirect", function(HookEvent $event) { $url = $event->arguments(0); if($url == "../") { $goto = wire("pages")->get(3062)->url; $event->arguments = array($goto); } }); But i need to check if current page have template of blog entry. How i can get current template name? In event data it is admin template.
Zeka Posted June 4, 2016 Author Posted June 4, 2016 LostKobrakai, thanks for help! Final solution wire()->addHookBefore("ProcessPageEdit::processSaveRedirect", function(HookEvent $event) { $url = $event->arguments(0); $page = $event->object->getPage(); if($page->template->name == 'blog-entry') { if($url == "../") { $goto = wire("pages")->get(3062)->url; $event->arguments = array($goto); } } }); 2
dotnetic Posted October 26, 2018 Posted October 26, 2018 @Zeka I would like to request adding a [SOLVED] to the title of this thread. This helps others who are looking for working solutions. 1
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