Jump to content

ProcessPageEdit Redirect after Save


Jo J
 Share

Recommended Posts

I've created a process module that saves pages under the Home > Admin > MyPages level in the admin.

The module has a list of those pages created with links to allow further editing via PW's normal Page Edit. Upon clicking it, the form opens for editing. To stay away from the Admin territory (hidden by default), I'd like to redirect back to the module's home after saving my edits but am not successful so far.

I've been trying a bunch of ways I see here in the forum & the docs. Among some that do not appear to trigger (from my ProcessMyApp.module.php) are:

1) Derived from my understanding of API doc

init() {
   parent::init();
   	//$this->wire()->processPageEdit->setRedirectPath('/myapp/');
	$this->wire()->processPageEdit->setRedirectUrl($this->config->urls->admin . '/myapp/');
   	
}

2) Derived from Ryan's /site/modules/RedirectPageEdit.module here

init() {
	parent::init();
   $this->wire()->session->addHookBefore('redirect', $this, 'redirectAfterSave');
   
}

3) Also derived from my understanding of API doc

init() {
 	parent::init();
	$this->wire()->addHookAfter('ProcessPageEdit::processSaveRedirect' , $this, 'redirectAfterSave');
}


The redirectAfterSave:

public function redirectAfterSave(HookEvent $event) {
        $process = $event->object;
        $page = $process->getPage();

        bd($event,'Tracy no see');
        if($page->template->name === self::module_template) {
            
            $event->arguments = array($this->config->urls->admin . 'myapp/');
        }
}


What could I be overlooking?

Tried in Processwire 3.0.243 & 3.0.244

Edited by Jo J
Tried with both the parent::init(); before & after
Link to comment
Share on other sites

I moved the pages out of under the Admin level & to the normal Pages level. and this worked:
 

public function init() {
	parent::init();
	$this->addHookAfter('Pages::saved', $this, 'redirectAfterSave');
}

public function redirectAfterSave(HookEvent $event) {
  $page = $event->arguments[0];

  if($page->template->name === self::module_template) {
  	$app_url = $this->config->urls->admin . 'myapp/';
  	$this->wire('session')->redirect($app_url);
  }
}

I need to do more reading on the Admin mechanics.

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