From f27feb2bbf4e8df665dbdb6bd8bbb15f880284a0 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 6 Apr 2018 06:46:42 -0400 Subject: [PATCH] Followup fix for issue processwire/processwire-issues#322 check for duplicate non-default language page name when creating new page --- .../LanguageSupport/LanguageSupportPageNames.module | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wire/modules/LanguageSupport/LanguageSupportPageNames.module b/wire/modules/LanguageSupport/LanguageSupportPageNames.module index 55cd74e6..4b15a524 100644 --- a/wire/modules/LanguageSupport/LanguageSupportPageNames.module +++ b/wire/modules/LanguageSupport/LanguageSupportPageNames.module @@ -565,8 +565,12 @@ class LanguageSupportPageNames extends WireData implements Module, ConfigurableM $key = "name$language"; if($value == $page->get($key)) continue; - // @todo uncomment in dev branch - // if(!$this->checkLanguagePageName($language, $page, $value, $inputfield)) continue; + // @todo make the following apply without debug+advanced mode after further testing on dev + if($this->wire('config')->debug && $this->wire('config')->advanced) { + $parentID = $page->parent_id; + if(!$parentID) $parentID = (int) $this->wire('input')->post('parent_id'); + if(!$this->checkLanguagePageName($language, $page, $parentID, $value, $inputfield)) continue; + } if($page->id) { $page->set($key, $value); @@ -581,12 +585,13 @@ class LanguageSupportPageNames extends WireData implements Module, ConfigurableM * * @param Language $language * @param Page $page + * @param int $parentID * @param string $value New page name * @param Wire|null $errorTarget Object to send error to (Inputfield likely) * @return bool True if all good, false if not * */ - public function checkLanguagePageName(Language $language, Page $page, $value, Wire $errorTarget = null) { + public function checkLanguagePageName(Language $language, Page $page, $parentID, $value, Wire $errorTarget = null) { // verify that it does not conflict with another page inheriting name from default language $isValid = true; $nameKey = "name$language->id"; @@ -603,7 +608,7 @@ class LanguageSupportPageNames extends WireData implements Module, ConfigurableM ")"; $query = $this->wire('database')->prepare($sql); - $query->bindValue(':parent_id', $page->parent_id, \PDO::PARAM_INT); + $query->bindValue(':parent_id', $parentID, \PDO::PARAM_INT); $query->bindValue(':newName', $value); $query->bindValue(':newName2', $value); $query->bindValue(':id', $page->id, \PDO::PARAM_INT);