Jump to content

[SOLVED] Redirect on "Save + Exit" / Hook for "Save + Exit" action


Zeka
 Share

Recommended Posts

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? 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
        }
    }
});
  • Like 2
Link to comment
Share on other sites

  • 2 years 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...