From c9fca292835b13ec4cc3247753ded23d0434857f Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Tue, 22 Aug 2017 11:22:27 -0400 Subject: [PATCH] Fix issue processwire/processwire-issues#344 using page name with not-equals operator in FieldtypePage selector --- wire/modules/Fieldtype/FieldtypePage.module | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/wire/modules/Fieldtype/FieldtypePage.module b/wire/modules/Fieldtype/FieldtypePage.module index 8db24241..9e749a76 100644 --- a/wire/modules/Fieldtype/FieldtypePage.module +++ b/wire/modules/Fieldtype/FieldtypePage.module @@ -743,14 +743,21 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule return parent::getMatchQuery($query, $table, $subfield, $operator, $value); - } else if(in_array($subfield, $names)) { + } else if(in_array($subfield, $names) || ($subfield == 'name' && $operator == '!=')) { if(!$database->isOperator($operator)) { throw new WireException("Operator '$operator' is not implemented in {$this->className}"); } - if(in_array($subfield, array('id', 'path', 'url'))) $subfield = 'data'; - + if($subfield == 'name') { + $value = $this->wire('sanitizer')->pageName($value); + $value = implode(',', $this->pages->findIDs("name=$value, include=all")); + if(empty($value)) $value = "0"; + $idstr = true; + } + + if(in_array($subfield, array('id', 'path', 'url', 'name'))) $subfield = 'data'; + // if a page path rather than page ID was provided, then we translate the path to an ID for API syntax convenience if($idstr || !ctype_digit("$value")) { if(is_null($idstr) && $subfield == 'data' && strpos($value, ',') !== false) {