1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-21 05:51:41 +02:00

Update FieldtypeOptions to support InputfieldTextTags as an input module

This commit is contained in:
Ryan Cramer
2021-04-22 12:55:24 -04:00
parent 83c58ca4a5
commit 290e28a249
2 changed files with 16 additions and 5 deletions

View File

@@ -179,6 +179,12 @@ class FieldtypeOptions extends FieldtypeMulti implements Module {
// assumed to be an option ID
$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)
$_value = $value; // save for second check

View File

@@ -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,9 +168,11 @@ 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)";
@@ -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 {