Jump to content

Redirect PageEdit to PageList after save


ryan
 Share

Recommended Posts

Adam had an idea and preference for making PageEdit return to PageList after saving, and he posted a snippet to make it happen in the FAQ section (thanks Adam!). I followed up with an alternate way using a module (something that won't get wiped out during upgrades). Posting again here since this is the Modules forum so the original topic can stay in the FAQ forum. Also thought this was a good example of how to make a simple module to customize ProcessWire for your preferences.

Once installed, every time you save a page, it'll return to the PageList drilled down to the page you were editing. Some people prefer this behavior (though I'm not one of them). To install, paste the following (or download the attached module) into /site/modules/RedirectPageEdit.module.

/site/modules/RedirectPageEdit.module

<?php                   
                        
class RedirectPageEdit extends WireData implements Module {
                        
        public static function getModuleInfo() {
                return array(
                        'title' => 'Redirect PageEdit',
                        'version' => 100, 
                        'summary' => 'Redirects PageEdit to return to PageList after save rather than edit again.',
                        'singular' => true, 
                        'autoload' => true, 
                        );
        }               
        
        public function init() {
                $this->session->addHookBefore('redirect', $this, 'myRedirect');
        }

        public function myRedirect(HookEvent $event) {
                if($this->process == 'ProcessPageEdit' && preg_match('{^\./\?id=(\d+)$}', $event->arguments[0], $m)) {
                        $event->arguments = array($this->config->urls->admin . "page/?open=$m[1]");
                }
        }
}

RedirectPageEdit.module

  • Like 1
Link to comment
Share on other sites

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...