From 290e28a249768aff7693a465316aecdd3c0ff991 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 22 Apr 2021 12:55:24 -0400 Subject: [PATCH] Update FieldtypeOptions to support InputfieldTextTags as an input module --- .../FieldtypeOptions/FieldtypeOptions.module | 8 +++++++- .../FieldtypeOptions/SelectableOptionConfig.php | 13 +++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/wire/modules/Fieldtype/FieldtypeOptions/FieldtypeOptions.module b/wire/modules/Fieldtype/FieldtypeOptions/FieldtypeOptions.module index 829dacb7..c3224197 100644 --- a/wire/modules/Fieldtype/FieldtypeOptions/FieldtypeOptions.module +++ b/wire/modules/Fieldtype/FieldtypeOptions/FieldtypeOptions.module @@ -177,7 +177,13 @@ class FieldtypeOptions extends FieldtypeMulti implements Module { } else if(is_int($value) || (is_string($value) && ctype_digit("$value"))) { // assumed to be an option ID - $value = $this->manager->getOptionsByID($field, array((int) $value)); + $value = $this->manager->getOptionsByID($field, array((int) $value)); + + } else if(is_string($value) && $field->get('inputfieldClass') === 'InputfieldTextTags') { + /** @var InputfieldTextTags $inputfield */ + $inputfield = $this->wire()->modules->getModule('InputfieldTextTags', array('noInit' => true)); + $value = $inputfield->tagStringToArray($value); + $value = $this->manager->getOptions($field, array('id' => $value)); } else if(is_string($value)) { // may be option 'title' (first) or option 'value' (second) diff --git a/wire/modules/Fieldtype/FieldtypeOptions/SelectableOptionConfig.php b/wire/modules/Fieldtype/FieldtypeOptions/SelectableOptionConfig.php index 83858af4..533222a7 100644 --- a/wire/modules/Fieldtype/FieldtypeOptions/SelectableOptionConfig.php +++ b/wire/modules/Fieldtype/FieldtypeOptions/SelectableOptionConfig.php @@ -156,6 +156,7 @@ class SelectableOptionConfig extends Wire { $labelSingle = $this->_('Single value'); $labelMulti = $this->_('Multiple values'); + $labelSortable = $this->_('Multiple sortable values'); $f = $modules->get('InputfieldSelect'); $f->attr('name', 'inputfieldClass'); @@ -167,15 +168,17 @@ class SelectableOptionConfig extends Wire { if($module instanceof ModulePlaceholder) { $module = $modules->getModule($module->className(), array('noInit' => true)); } - if($module instanceof InputfieldSelect) { + if($module instanceof InputfieldSelect || $module instanceof InputfieldHasSelectableOptions) { $name = str_replace('Inputfield', '', $module->className()); - if($module instanceof InputfieldSelectMultiple) { + if($module instanceof InputfieldHasSortableValue) { + $name .= " ($labelSortable)"; + } else if($module instanceof InputfieldSelectMultiple) { $name .= " ($labelMulti)"; } else { $name .= " ($labelSingle)"; } $f->addOption($module->className(), $name); - } + } } $value = $field->get('inputfieldClass'); if(!$value) $value = 'InputfieldSelect'; @@ -210,7 +213,9 @@ class SelectableOptionConfig extends Wire { foreach($options as $option) { $f->addOption($option->id, $option->title); } - $f->attr('value', $field->get('initValue')); + $initValue = $field->get('initValue'); + if($f instanceof InputfieldHasArrayValue && !is_array($initValue) && !empty($initValue)) $initValue = explode(' ', $initValue); + $f->attr('value', $initValue); if(!$field->required && !$field->requiredIf) { $f->notes = $this->_('Please note: your selections here do not become active unless a value is *always* required for this field. See the "required" option on the Input tab of your field settings.'); } else {