From 683e24e0102d064cc506d9b167932f7b513c5c4a Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Mon, 6 Aug 2018 11:31:35 -0400 Subject: [PATCH] Add an update to accommodate request in processwire/processwire-issues#648 for wording of warning message when a 3rd party hook has changed a page's name behind the scenes after it was saved --- .../ProcessPageAdd/ProcessPageAdd.module | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module b/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module index ac91fee6..de9f69dc 100644 --- a/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module +++ b/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module @@ -16,6 +16,7 @@ * @method InputfieldForm buildForm() * @method bool processInput(InputfieldForm $form) * @method array getAllowedTemplates($parent = null) + * @method string nameChangedWarning(Page $page, $namePrevious) * */ @@ -1063,6 +1064,21 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit ) ); } + + /** + * Hook called when the page's name changed during save + * + * @param Page $page + * @param $namePrevious + * @return string Warning message + * + */ + protected function ___nameChangedWarning(Page $page, $namePrevious) { + return sprintf( + $this->_('Warning, the name you selected "%1$s" has been changed to "%2$s".'), + $namePrevious, $page->name + ); + } /** * Save the submitted page add form @@ -1155,11 +1171,9 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit $this->createdPageMessage($this->page); if($pageName != $this->page->name) { - $this->error(sprintf( - $this->_('Warning, the name you selected "%1$s" was already in use and has been changed to "%2$s".'), - $pageName, $this->page->name - )); - } + $warning = $this->nameChangedWarning($this->page, $pageName); + if($warning) $this->warning($warning); + } if($publishNow && $publishAdd) { $this->session->redirect("./?parent_id={$this->page->parent_id}&template_id={$this->page->template->id}");