diff --git a/wire/modules/Fieldtype/FieldtypeModule.module b/wire/modules/Fieldtype/FieldtypeModule.module index 4a35e022..3251e210 100644 --- a/wire/modules/Fieldtype/FieldtypeModule.module +++ b/wire/modules/Fieldtype/FieldtypeModule.module @@ -8,7 +8,7 @@ * For documentation about the fields used in this class, please see: * /wire/core/Fieldtype.php * - * ProcessWire 3.x, Copyright 2016 by Ryan Cramer + * ProcessWire 3.x, Copyright 2021 by Ryan Cramer * https://processwire.com * */ @@ -21,7 +21,7 @@ class FieldtypeModule extends Fieldtype { 'version' => 101, 'summary' => 'Field that stores a reference to another module', 'permanent' => true, - ); + ); } public function getBlankValue(Page $page, Field $field) { @@ -51,8 +51,9 @@ class FieldtypeModule extends Fieldtype { public function ___wakeupValue(Page $page, Field $field, $value) { if(empty($value)) return $this->getBlankValue($page, $field); - if($field->get('instantiateModule')) return $this->wire('modules')->get($value); - return $this->wire('modules')->getModuleClass((int) $value); + $modules = $this->wire()->modules; + if($field->get('instantiateModule')) return $modules->get($value); + return $modules->getModuleClass((int) $value); } public function ___sleepValue(Page $page, Field $field, $value) { @@ -66,15 +67,14 @@ class FieldtypeModule extends Fieldtype { public function getInputfield(Page $page, Field $field) { - /** @var Modules $modules */ - $modules = $this->wire('modules'); + $modules = $this->wire()->modules; $inputfieldClass = $field->get('inputfieldClass'); $inputfieldClass = $inputfieldClass ? $inputfieldClass : 'InputfieldSelect'; /** @var InputfieldSelect $inputfield */ $inputfield = $modules->get($inputfieldClass); - if(!$inputfield) $inputfield = $this->modules->get('InputfieldSelect'); + if(!$inputfield) $inputfield = $modules->get('InputfieldSelect'); $inputfield->attr('name', $field->name); $inputfield->class = $this->className(); @@ -82,7 +82,7 @@ class FieldtypeModule extends Fieldtype { foreach($modules as $module) { $found = false; - $ns = $this->modules->getModuleNamespace($module); + $ns = $modules->getModuleNamespace($module); $parents = wireClassParents($ns ? "$ns$module" : "$module"); $moduleTypes = $field->get('moduleTypes'); if($moduleTypes) foreach($moduleTypes as $moduleType) { @@ -99,7 +99,13 @@ class FieldtypeModule extends Fieldtype { } else if($labelField === 'title-summary') { $info = $modules->getModuleInfoVerbose($module); $label = !empty($info['title']) ? $info['title'] : (string) $module; - if(!empty($info['summary'])) $label .= " [span.detail] • " . $info['summary'] . ' [/span]'; + if(!empty($info['summary'])) { + if($inputfieldClass === 'InputfieldRadios') { + $label .= " [span.detail] • $info[summary] [/span]"; + } else { + $label .= " • $info[summary]"; + } + } } else { $label = (string) $module; } @@ -128,14 +134,15 @@ class FieldtypeModule extends Fieldtype { public function ___getConfigInputfields(Field $field) { + $modules = $this->wire()->modules; $inputfields = parent::___getConfigInputfields($field); $lastType = ''; /** @var InputfieldCheckboxes $f */ - $f = $this->modules->get("InputfieldCheckboxes"); + $f = $modules->get("InputfieldCheckboxes"); $f->attr('name', 'moduleTypes'); - foreach($this->modules as $module) { + foreach($modules as $module) { if(strpos($module->className(), 'AdminTheme') === 0) { $matches = array('', 'AdminTheme'); } else { @@ -156,7 +163,7 @@ class FieldtypeModule extends Fieldtype { $inputfields->append($f); /** @var InputfieldCheckbox $f */ - $f = $this->modules->get("InputfieldCheckbox"); + $f = $modules->get("InputfieldCheckbox"); $f->attr('name', 'instantiateModule'); $f->label = $this->_('Make this field an instance of the selected module?'); $f->description = $this->_('If checked, the field value will be an actual instance of the selected module. If not checked, the field value will be a string containing the class name of the module.'); // instantiate module description @@ -164,7 +171,7 @@ class FieldtypeModule extends Fieldtype { $inputfields->add($f); /** @var InputfieldRadios $f */ - $f = $this->modules->get('InputfieldRadios'); + $f = $modules->get('InputfieldRadios'); $f->label = $this->_('Options Label'); $f->attr('name', 'labelField'); $f->addOption('', $this->_('Name')); @@ -175,7 +182,7 @@ class FieldtypeModule extends Fieldtype { $inputfields->add($f); /** @var InputfieldRadios $f */ - $f = $this->modules->get('InputfieldRadios'); + $f = $modules->get('InputfieldRadios'); $f->label = $this->_('Input Type'); $f->attr('name', 'inputfieldClass'); $f->addOption('', $this->_('Select')); @@ -185,7 +192,7 @@ class FieldtypeModule extends Fieldtype { $inputfields->add($f); /** @var InputfieldCheckbox $f */ - $f = $this->modules->get('InputfieldCheckbox'); + $f = $modules->get('InputfieldCheckbox'); $f->label = $this->_('Show a “None” option?'); $f->attr('name', 'showNoneOption'); if($field->get('showNoneOption')) $f->attr('checked', 'checked'); @@ -193,14 +200,16 @@ class FieldtypeModule extends Fieldtype { $inputfields->add($f); /** @var InputfieldRadios $f */ - $f = $this->modules->get('InputfieldRadios'); + $f = $modules->get('InputfieldRadios'); $f->attr('name', 'blankType'); $f->label = $this->_('Blank value type'); $f->addOption('null', 'Null'); $f->addOption('zero', 'Integer 0'); $f->addOption('false', 'Boolean false'); $f->addOption('placeholder', 'ModulePlaceholder instance'); - $f->attr('value', $field->get('blankType')); + $value = $field->get('blankType'); + if($value === null) $value = 'null'; + $f->val($value); $inputfields->add($f); return $inputfields; @@ -208,7 +217,7 @@ class FieldtypeModule extends Fieldtype { public function ___getCompatibleFieldtypes(Field $field) { $fieldtypes = $this->wire(new Fieldtypes()); - foreach($this->wire('fieldtypes') as $fieldtype) { + foreach($this->wire()->fieldtypes as $fieldtype) { if($fieldtype instanceof FieldtypeModule) $fieldtypes->add($fieldtype); } return $fieldtypes;