Jump to content

Change redirect url on page deletion from page delete tab


Zeka
 Share

Recommended Posts

Hi.

Hi.

By default when you delete a page from delete tab on page edit screen it redirects to URL like 'admin/page/?open=1033' where 1033 is ID of the parent of deleted page. 

I'm using a custom process module for managing news pages, so I want to redirect to my custom trash page. 

This URL is hardcoded in ProcessPageEdit module https://github.com/processwire/processwire/blob/master/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module#L2434

AFAICS the only way to change it is to hook  ProcessPageEdit::buildFormDelete, remove default checkbox, add custom one and then hook to ProcessPageEdit::processInput, execute custom delete function.

Is it? Maybe there is easier way? 

Link to comment
Share on other sites

You can hook Session::redirect and check the redirect URL and the current process. Not perfect, but as far as I can see the deletePage() method uses a redirect URL that is unique in ProcessPageEdit and is therefore identifiable as coming from that method.

$wire->addHookBefore('Session::redirect', function(HookEvent $event) {
	$url = $event->arguments(0);
	if($this->process == 'ProcessPageEdit') {
		$admin_url = $event->wire('config')->urls->admin;
		if(strpos($url, $admin_url . 'page/?open=') === 0) {
			$event->arguments(0, '/your/custom/url/');
		}
	}
});

 

  • Like 1
Link to comment
Share on other sites

@Robin S Thanks. For now, I ended up with

....
$this->wire()->addHookAfter('Pages::trashed(template=link-block|post|tag)', $this, 'customRedirectOnDelete');

public function hookRedirectOnLinkBlockDelete($event) {
		$event->wire()->addHookBefore('Session::redirect', function(HookEvent $event) {
			$url = $event->arguments(0);
			if($this->process == 'ProcessPageEdit') {
				$admin_url = $event->wire('config')->urls->admin;
				if(strpos($url, $admin_url . 'page/?open=') === 0) {
					$event->arguments(0, '../trash/');
			}
		}
	});
}

 

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