From 4ef5ebc8fbcf51e46efe51ba68d1d5846aecaaa5 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Tue, 19 Mar 2019 10:29:36 -0400 Subject: [PATCH] Fix issue processwire/processwire-issues#364 --- wire/core/PagesType.php | 17 +++++++++++++++++ .../InputfieldSelector.module | 13 +++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/wire/core/PagesType.php b/wire/core/PagesType.php index 93cf0685..549343a3 100644 --- a/wire/core/PagesType.php +++ b/wire/core/PagesType.php @@ -269,6 +269,23 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable { return $pages; } + /** + * Given a Selector string, return the page IDs that match + * + * @param string $selectorString + * @param array $options + * @return array + * @since 3.0.128 + * @see Pages::findIDs() + * + */ + public function findIDs($selectorString, $options = array()) { + if(!isset($options['findAll'])) $options['findAll'] = true; + if(empty($options['caller'])) $options['caller'] = $this->className() . ".findIDs($selectorString)"; + $ids = $this->wire('pages')->findIDs($this->selectorString($selectorString), $options); + return $ids; + } + /** * Get the first match of your selector string * diff --git a/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module b/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module index 5c3e142b..8ed7b861 100644 --- a/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module +++ b/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module @@ -7,7 +7,7 @@ * Code by Ryan Cramer * Sponsored by Avoine * - * ProcessWire 3.x, Copyright 2016 by Ryan Cramer + * ProcessWire 3.x, Copyright 2019 by Ryan Cramer * https://processwire.com * * @todo add support for "custom: OR-group" option (https://processwire.com/talk/topic/13116-or-selecters-for-different-fields/) @@ -162,6 +162,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule { 'timePlaceholder', 'previewColumns', 'limitFields', + 'maxUsers', ); /** @@ -1938,9 +1939,13 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule { $ids = array(); foreach($s->values as $key => $name) { $property = ctype_digit("$name") ? 'id' : 'name'; - $users = $this->wire('users')->find("$property$s->operator" . - $this->wire('sanitizer')->selectorValue($this->wire('sanitizer')->pageNameUTF8($name))); - foreach($users as $u) $ids[$u->id] = $u->id; + $operator = $s->operator === '!=' ? '=' : $s->operator; + if($property === 'name') { + $value = $this->wire('sanitizer')->selectorValue($this->wire('sanitizer')->pageNameUTF8($name)); + } else { + $value = (int) $name; // id + } + $ids = array_merge($ids, $this->wire('users')->findIDs("$property$operator$value")); } if($s->operator != '=' && $s->operator != '!=') { $userSelectors->remove($s);