Jump to content

Quick tip: Have PW return to pagelist after saving a page


Adam Kiss
 Share

Recommended Posts

Edit: THIS HACK HAS BEEN SURPASSED BY THIS PLUGIN: http://processwire.com/talk/index.php/topic,255.0.html PLEASE USE IT INSTEAD OF THIS QUICK TIP/HACK

Are you one of those assholes, who just love to fiddle with everything so it suits your needs?

No worries. Me too.

And I really hate the fact, that processwire stays on the 'Edit page' after saving page, so here is a quick tip: [non-tested with the fantastic Antti's AdminBar]:

Locate the file /wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module and change line 143 from:

<?php
if(!$this->redirectUrl) $this->redirectUrl = "./?id={$this->page->id}"; 

to

<?php
if(!$this->redirectUrl) $this->redirectUrl = "/processwire/page/?open={$this->page->id}"; 

And voilà! ProcessWire now opens PageList with awesome list animation after saving.

Note: Do not look for '<?php' near that line. That was added here just kick in code coloring. Important is just that if(!$this... part

Link to comment
Share on other sites

Adam, good tip. The only potential problem I can see here is that when you upgrade that update will get wiped out. Here's a way to do it in an upgrade-friendly way.

Paste this into a file called RedirectPageEdit.module in /site/modules/. Or download it from the thread in the Modules forum (I'm going to post the file there).

/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]");
                }
        }
}
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...