1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 18:24:57 +02:00

Add new 'deletedPage()' hook method in ProcessPageEdit (recently requested by someone)

This commit is contained in:
Ryan Cramer
2021-04-16 10:43:40 -04:00
parent ce7df80eac
commit 6a04f1f08f

View File

@@ -27,6 +27,7 @@
* @method array getSubmitActions() * @method array getSubmitActions()
* @method bool processSubmitAction($value) * @method bool processSubmitAction($value)
* @method void processSaveRedirect($redirectUrl) * @method void processSaveRedirect($redirectUrl)
* @method void deletedPage($page, $redirectUrl, $trashed = false)
* @method InputfieldForm buildForm(InputfieldForm $form) * @method InputfieldForm buildForm(InputfieldForm $form)
* @method InputfieldWrapper buildFormContent() * @method InputfieldWrapper buildFormContent()
* @method InputfieldWrapper buildFormChildren() * @method InputfieldWrapper buildFormChildren()
@@ -587,7 +588,8 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
$class = ''; $class = '';
$numFields = count($this->fields); $numFields = count($this->fields);
$out = "<p id='PageIDIndicator' class='$class'>" . ($this->page->id ? $this->page->id : "New") . "</p>"; // $out = "<p id='PageIDIndicator' class='$class'>" . ($this->page->id ? $this->page->id : "New") . "</p>";
$out = "<p id='PageIDIndicator' class='$class'>{$this->page->id}</p>";
$description = $this->form->getSetting('description'); $description = $this->form->getSetting('description');
if($description) { if($description) {
@@ -2436,24 +2438,26 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
* *
*/ */
protected function deletePage() { protected function deletePage() {
$page = $this->page;
if(!$this->page->trashable(true)) { if(!$page->trashable(true)) {
$this->error($this->_('This page is not deleteable')); $this->error($this->_('This page is not deleteable'));
return false; return false;
} }
$afterDeleteRedirect = $this->config->urls->admin . "page/?open={$this->parent->id}"; $redirectUrl = $this->wire()->config->urls->admin . "page/?open={$this->parent->id}";
if($this->wire('page')->process != $this->className()) $afterDeleteRedirect = "../"; if($this->wire()->page->process != $this->className()) $redirectUrl = "../";
$pagePath = $this->page->path(); $pagePath = $page->path();
if(($this->isTrash || $this->page->template->noTrash) && $this->page->deleteable()) { if(($this->isTrash || $page->template->noTrash) && $page->deleteable()) {
$this->session->message(sprintf($this->_('Deleted page: %s'), $pagePath)); // Page deleted message $this->wire()->session->message(sprintf($this->_('Deleted page: %s'), $pagePath)); // Page deleted message
$this->pages->delete($this->page, true); $this->pages->delete($page, true);
$this->session->redirect($afterDeleteRedirect); $this->deletedPage($page, $redirectUrl, false);
} else if($this->pages->trash($this->page)) { } else if($this->pages->trash($page)) {
$this->session->message(sprintf($this->_('Moved page to trash: %s'), $pagePath)); // Page moved to trash message $this->wire()->session->message(sprintf($this->_('Moved page to trash: %s'), $pagePath)); // Page moved to trash message
$this->session->redirect($afterDeleteRedirect); $this->deletedPage($page, $redirectUrl, true);
} else { } else {
$this->error($this->_('Unable to move page to trash')); // Page can't be moved to the trash error $this->error($this->_('Unable to move page to trash')); // Page can't be moved to the trash error
@@ -2462,6 +2466,20 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
return true; return true;
} }
/**
* Called after a page has been deleted or trashed, performs redirect
*
* @param Page $page Page that was deleted or trashed
* @param string $redirectUrl URL that should be redirected to
* @param bool $trashed True if page was trashed rather than deleted
* @since 3.0.173
*
*/
protected function ___deletedPage($page, $redirectUrl, $trashed = false) {
if($page || $trashed) {} // ignore
$this->wire()->session->location($redirectUrl);
}
/** /**
* Save only the fields posted via ajax * Save only the fields posted via ajax