mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 17:54:44 +02:00
Fix issue processwire/processwire-issues#1069 plus other minor code updates to FieldtypeModule
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
* For documentation about the fields used in this class, please see:
|
* For documentation about the fields used in this class, please see:
|
||||||
* /wire/core/Fieldtype.php
|
* /wire/core/Fieldtype.php
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -21,7 +21,7 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
'version' => 101,
|
'version' => 101,
|
||||||
'summary' => 'Field that stores a reference to another module',
|
'summary' => 'Field that stores a reference to another module',
|
||||||
'permanent' => true,
|
'permanent' => true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlankValue(Page $page, Field $field) {
|
public function getBlankValue(Page $page, Field $field) {
|
||||||
@@ -51,8 +51,9 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
|
|
||||||
public function ___wakeupValue(Page $page, Field $field, $value) {
|
public function ___wakeupValue(Page $page, Field $field, $value) {
|
||||||
if(empty($value)) return $this->getBlankValue($page, $field);
|
if(empty($value)) return $this->getBlankValue($page, $field);
|
||||||
if($field->get('instantiateModule')) return $this->wire('modules')->get($value);
|
$modules = $this->wire()->modules;
|
||||||
return $this->wire('modules')->getModuleClass((int) $value);
|
if($field->get('instantiateModule')) return $modules->get($value);
|
||||||
|
return $modules->getModuleClass((int) $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ___sleepValue(Page $page, Field $field, $value) {
|
public function ___sleepValue(Page $page, Field $field, $value) {
|
||||||
@@ -66,15 +67,14 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
|
|
||||||
public function getInputfield(Page $page, Field $field) {
|
public function getInputfield(Page $page, Field $field) {
|
||||||
|
|
||||||
/** @var Modules $modules */
|
$modules = $this->wire()->modules;
|
||||||
$modules = $this->wire('modules');
|
|
||||||
|
|
||||||
$inputfieldClass = $field->get('inputfieldClass');
|
$inputfieldClass = $field->get('inputfieldClass');
|
||||||
$inputfieldClass = $inputfieldClass ? $inputfieldClass : 'InputfieldSelect';
|
$inputfieldClass = $inputfieldClass ? $inputfieldClass : 'InputfieldSelect';
|
||||||
|
|
||||||
/** @var InputfieldSelect $inputfield */
|
/** @var InputfieldSelect $inputfield */
|
||||||
$inputfield = $modules->get($inputfieldClass);
|
$inputfield = $modules->get($inputfieldClass);
|
||||||
if(!$inputfield) $inputfield = $this->modules->get('InputfieldSelect');
|
if(!$inputfield) $inputfield = $modules->get('InputfieldSelect');
|
||||||
|
|
||||||
$inputfield->attr('name', $field->name);
|
$inputfield->attr('name', $field->name);
|
||||||
$inputfield->class = $this->className();
|
$inputfield->class = $this->className();
|
||||||
@@ -82,7 +82,7 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
|
|
||||||
foreach($modules as $module) {
|
foreach($modules as $module) {
|
||||||
$found = false;
|
$found = false;
|
||||||
$ns = $this->modules->getModuleNamespace($module);
|
$ns = $modules->getModuleNamespace($module);
|
||||||
$parents = wireClassParents($ns ? "$ns$module" : "$module");
|
$parents = wireClassParents($ns ? "$ns$module" : "$module");
|
||||||
$moduleTypes = $field->get('moduleTypes');
|
$moduleTypes = $field->get('moduleTypes');
|
||||||
if($moduleTypes) foreach($moduleTypes as $moduleType) {
|
if($moduleTypes) foreach($moduleTypes as $moduleType) {
|
||||||
@@ -99,7 +99,13 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
} else if($labelField === 'title-summary') {
|
} else if($labelField === 'title-summary') {
|
||||||
$info = $modules->getModuleInfoVerbose($module);
|
$info = $modules->getModuleInfoVerbose($module);
|
||||||
$label = !empty($info['title']) ? $info['title'] : (string) $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 {
|
} else {
|
||||||
$label = (string) $module;
|
$label = (string) $module;
|
||||||
}
|
}
|
||||||
@@ -128,14 +134,15 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
|
|
||||||
public function ___getConfigInputfields(Field $field) {
|
public function ___getConfigInputfields(Field $field) {
|
||||||
|
|
||||||
|
$modules = $this->wire()->modules;
|
||||||
$inputfields = parent::___getConfigInputfields($field);
|
$inputfields = parent::___getConfigInputfields($field);
|
||||||
$lastType = '';
|
$lastType = '';
|
||||||
|
|
||||||
/** @var InputfieldCheckboxes $f */
|
/** @var InputfieldCheckboxes $f */
|
||||||
$f = $this->modules->get("InputfieldCheckboxes");
|
$f = $modules->get("InputfieldCheckboxes");
|
||||||
$f->attr('name', 'moduleTypes');
|
$f->attr('name', 'moduleTypes');
|
||||||
|
|
||||||
foreach($this->modules as $module) {
|
foreach($modules as $module) {
|
||||||
if(strpos($module->className(), 'AdminTheme') === 0) {
|
if(strpos($module->className(), 'AdminTheme') === 0) {
|
||||||
$matches = array('', 'AdminTheme');
|
$matches = array('', 'AdminTheme');
|
||||||
} else {
|
} else {
|
||||||
@@ -156,7 +163,7 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
$inputfields->append($f);
|
$inputfields->append($f);
|
||||||
|
|
||||||
/** @var InputfieldCheckbox $f */
|
/** @var InputfieldCheckbox $f */
|
||||||
$f = $this->modules->get("InputfieldCheckbox");
|
$f = $modules->get("InputfieldCheckbox");
|
||||||
$f->attr('name', 'instantiateModule');
|
$f->attr('name', 'instantiateModule');
|
||||||
$f->label = $this->_('Make this field an instance of the selected module?');
|
$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
|
$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);
|
$inputfields->add($f);
|
||||||
|
|
||||||
/** @var InputfieldRadios $f */
|
/** @var InputfieldRadios $f */
|
||||||
$f = $this->modules->get('InputfieldRadios');
|
$f = $modules->get('InputfieldRadios');
|
||||||
$f->label = $this->_('Options Label');
|
$f->label = $this->_('Options Label');
|
||||||
$f->attr('name', 'labelField');
|
$f->attr('name', 'labelField');
|
||||||
$f->addOption('', $this->_('Name'));
|
$f->addOption('', $this->_('Name'));
|
||||||
@@ -175,7 +182,7 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
$inputfields->add($f);
|
$inputfields->add($f);
|
||||||
|
|
||||||
/** @var InputfieldRadios $f */
|
/** @var InputfieldRadios $f */
|
||||||
$f = $this->modules->get('InputfieldRadios');
|
$f = $modules->get('InputfieldRadios');
|
||||||
$f->label = $this->_('Input Type');
|
$f->label = $this->_('Input Type');
|
||||||
$f->attr('name', 'inputfieldClass');
|
$f->attr('name', 'inputfieldClass');
|
||||||
$f->addOption('', $this->_('Select'));
|
$f->addOption('', $this->_('Select'));
|
||||||
@@ -185,7 +192,7 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
$inputfields->add($f);
|
$inputfields->add($f);
|
||||||
|
|
||||||
/** @var InputfieldCheckbox $f */
|
/** @var InputfieldCheckbox $f */
|
||||||
$f = $this->modules->get('InputfieldCheckbox');
|
$f = $modules->get('InputfieldCheckbox');
|
||||||
$f->label = $this->_('Show a “None” option?');
|
$f->label = $this->_('Show a “None” option?');
|
||||||
$f->attr('name', 'showNoneOption');
|
$f->attr('name', 'showNoneOption');
|
||||||
if($field->get('showNoneOption')) $f->attr('checked', 'checked');
|
if($field->get('showNoneOption')) $f->attr('checked', 'checked');
|
||||||
@@ -193,14 +200,16 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
$inputfields->add($f);
|
$inputfields->add($f);
|
||||||
|
|
||||||
/** @var InputfieldRadios $f */
|
/** @var InputfieldRadios $f */
|
||||||
$f = $this->modules->get('InputfieldRadios');
|
$f = $modules->get('InputfieldRadios');
|
||||||
$f->attr('name', 'blankType');
|
$f->attr('name', 'blankType');
|
||||||
$f->label = $this->_('Blank value type');
|
$f->label = $this->_('Blank value type');
|
||||||
$f->addOption('null', 'Null');
|
$f->addOption('null', 'Null');
|
||||||
$f->addOption('zero', 'Integer 0');
|
$f->addOption('zero', 'Integer 0');
|
||||||
$f->addOption('false', 'Boolean false');
|
$f->addOption('false', 'Boolean false');
|
||||||
$f->addOption('placeholder', 'ModulePlaceholder instance');
|
$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);
|
$inputfields->add($f);
|
||||||
|
|
||||||
return $inputfields;
|
return $inputfields;
|
||||||
@@ -208,7 +217,7 @@ class FieldtypeModule extends Fieldtype {
|
|||||||
|
|
||||||
public function ___getCompatibleFieldtypes(Field $field) {
|
public function ___getCompatibleFieldtypes(Field $field) {
|
||||||
$fieldtypes = $this->wire(new Fieldtypes());
|
$fieldtypes = $this->wire(new Fieldtypes());
|
||||||
foreach($this->wire('fieldtypes') as $fieldtype) {
|
foreach($this->wire()->fieldtypes as $fieldtype) {
|
||||||
if($fieldtype instanceof FieldtypeModule) $fieldtypes->add($fieldtype);
|
if($fieldtype instanceof FieldtypeModule) $fieldtypes->add($fieldtype);
|
||||||
}
|
}
|
||||||
return $fieldtypes;
|
return $fieldtypes;
|
||||||
|
Reference in New Issue
Block a user