mirror of
https://github.com/processwire/processwire.git
synced 2025-08-17 20:11:46 +02:00
Update FieldtypeText to support custom selection of Inputfield (so long as it implements InputfieldHasTextValue), plus some other minor updates.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
* For documentation about the fields used in this class, please see:
|
||||
* /wire/core/Fieldtype.php
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*
|
||||
@@ -19,7 +19,7 @@ class FieldtypeText extends Fieldtype {
|
||||
public static function getModuleInfo() {
|
||||
return array(
|
||||
'title' => 'Text',
|
||||
'version' => 101,
|
||||
'version' => 102,
|
||||
'summary' => 'Field that stores a single line of text',
|
||||
'permanent' => true,
|
||||
);
|
||||
@@ -93,9 +93,11 @@ class FieldtypeText extends Fieldtype {
|
||||
$textformatters = $field->get('textformatters');
|
||||
|
||||
if($this->allowTextFormatters() && is_array($textformatters)) {
|
||||
$modules = $this->wire()->modules;
|
||||
foreach($textformatters as $name) {
|
||||
if(!$textformatter = $this->wire('modules')->get($name)) continue;
|
||||
$textformatter->formatValue($page, $field, $value);
|
||||
/** @var Textformatter $textformatter */
|
||||
$textformatter = $modules->get($name);
|
||||
if($textformatter) $textformatter->formatValue($page, $field, $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +129,11 @@ class FieldtypeText extends Fieldtype {
|
||||
*
|
||||
*/
|
||||
public function getInputfield(Page $page, Field $field) {
|
||||
$inputField = $this->wire('modules')->get('InputfieldText');
|
||||
return $inputField;
|
||||
$modules = $this->wire()->modules;
|
||||
$inputfieldClass = $field->get('inputfieldClass');
|
||||
$inputfield = $inputfieldClass ? $modules->getModule($inputfieldClass) : null;
|
||||
if(!$inputfield) $inputfield = $modules->get('InputfieldText');
|
||||
return $inputfield;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,32 +178,61 @@ class FieldtypeText extends Fieldtype {
|
||||
*/
|
||||
public function ___getConfigInputfields(Field $field) {
|
||||
$inputfields = parent::___getConfigInputfields($field);
|
||||
if($this->allowTextFormatters()) {
|
||||
/** @var Modules $modules */
|
||||
$modules = $this->wire('modules');
|
||||
$textformatters = $modules->findByPrefix('Textformatter');
|
||||
|
||||
if(count($textformatters)) {
|
||||
/** @var InputfieldAsmSelect $f */
|
||||
$f = $this->modules->get('InputfieldAsmSelect');
|
||||
$f->attr('name', 'textformatters');
|
||||
$f->label = $this->_('Text Formatters');
|
||||
if(!$this->allowTextFormatters()) return $inputfields;
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$textformatters = $modules->findByPrefix('Textformatter');
|
||||
|
||||
if(!count($textformatters)) return $inputfields;
|
||||
|
||||
/** @var InputfieldFieldset $fieldset */
|
||||
$fieldset = $modules->get('InputfieldFieldset');
|
||||
$fieldset->attr('name', '_text_fieldset');
|
||||
$fieldset->label = $this->_('Text settings');
|
||||
$fieldset->icon = 'text-width';
|
||||
$inputfields->add($fieldset);
|
||||
|
||||
/** @var InputfieldAsmSelect $f */
|
||||
$f = $this->modules->get('InputfieldAsmSelect');
|
||||
$f->attr('name', 'textformatters');
|
||||
$f->label = $this->_('Text formatters');
|
||||
|
||||
foreach($textformatters as $moduleName) {
|
||||
$info = $modules->getModuleInfo($moduleName);
|
||||
$f->addOption($moduleName, "$info[title]");
|
||||
}
|
||||
|
||||
$value = $field->get('textformatters');
|
||||
if(!is_array($value)) $value = array();
|
||||
$f->val($value);
|
||||
$f->description = $this->_('If you want to apply any automatic formatting to the field when it is prepared for output, select one or more text formatters above. If you select more than one, drag them into the order they should be applied.');
|
||||
$f->notes = $this->_('For plain text fields that will not contain HTML or markup, we recommend selecting the **HTML Entity Encoder** option above.');
|
||||
|
||||
$inputfields->add($f);
|
||||
}
|
||||
foreach($textformatters as $moduleName) {
|
||||
$info = $modules->getModuleInfo($moduleName);
|
||||
$f->addOption($moduleName, "$info[title]");
|
||||
}
|
||||
|
||||
$value = $field->get('textformatters');
|
||||
if(!is_array($value)) $value = array();
|
||||
$f->val($value);
|
||||
$f->description =
|
||||
$this->_('If you want to apply any automatic formatting to the field when it is prepared for output, select one or more text formatters here.') . ' ' .
|
||||
$this->_('If you select more than one, drag them into the order they should be applied.') . ' ' .
|
||||
sprintf($this->_('Find more in the [text formatter modules directory](%s).'), 'https://processwire.com/modules/category/textformatter/');
|
||||
$f->notes =
|
||||
$this->_('For plain text fields that will not contain HTML or markup, we recommend selecting the **HTML Entity Encoder** option above.');
|
||||
$fieldset->add($f);
|
||||
|
||||
if($field->type->className() === 'FieldtypeText') {
|
||||
/** @var InputfieldSelect $field */
|
||||
$defaultLabel = $this->_('Default');
|
||||
$f = $this->modules->get('InputfieldRadios');
|
||||
$f->attr('name', 'inputfieldClass');
|
||||
$f->label = $this->_('Input module');
|
||||
$f->description = $this->_('Save after changing this as it may affect what settings are available on the “Input” tab.');
|
||||
$f->addOption('', $this->_('Text') . " [span.detail] - $defaultLabel [/span]");
|
||||
foreach($modules->findByPrefix('Inputfield', 2) as $moduleName => $moduleInfo) {
|
||||
if($moduleName === 'InputfieldText') continue;
|
||||
if(stripos($moduleName, 'textarea') !== false) continue;
|
||||
if(!wireInstanceOf($moduleName, 'InputfieldHasTextValue')) continue;
|
||||
$f->addOption($moduleName, "$moduleInfo[title] [span.detail] - $moduleInfo[summary] [/span]");
|
||||
}
|
||||
$f->val((string) $field->get('inputfieldClass'));
|
||||
$f->collapsed = Inputfield::collapsedBlank;
|
||||
$fieldset->add($f);
|
||||
}
|
||||
|
||||
|
||||
return $inputfields;
|
||||
}
|
||||
|
||||
|
@@ -250,7 +250,7 @@ class FieldtypeTextareaHelper extends Wire {
|
||||
$editURL = $this->wire('config')->urls->admin . "setup/field/edit?id=$field->id";
|
||||
$modulesURL = $this->wire('config')->urls->admin . "module/";
|
||||
$inputfieldClass = $field->get('inputfieldClass');
|
||||
$findURL = "http://modules.processwire.com/search/?q=$inputfieldClass";
|
||||
$findURL = "https://processwire.com/search/?q=$inputfieldClass&t=Modules";
|
||||
$tab = '<br /> ';
|
||||
|
||||
$note =
|
||||
|
@@ -17,7 +17,7 @@
|
||||
* @property bool $valueAddOption If value attr set from API (only) that is not an option, add it as an option? (default=false) 3.0.171+
|
||||
*
|
||||
*/
|
||||
class InputfieldSelect extends Inputfield {
|
||||
class InputfieldSelect extends Inputfield implements InputfieldHasSelectableOptions {
|
||||
|
||||
/**
|
||||
* Options specific to this Select
|
||||
@@ -82,6 +82,21 @@ class InputfieldSelect extends Inputfield {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add selectable option with label, optionally for specific language
|
||||
*
|
||||
* @param string|int $value
|
||||
* @param string $label
|
||||
* @param Language|null $language
|
||||
* @return $this
|
||||
* @since 3.0.176
|
||||
*
|
||||
*/
|
||||
public function addOptionLabel($value, $label, $language = null) {
|
||||
$this->optionLanguageLabel($language, $value, $label);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add multiple options at once
|
||||
*
|
||||
|
@@ -125,7 +125,7 @@ class InputfieldTextarea extends InputfieldText {
|
||||
* Process input
|
||||
*
|
||||
* @param WireInputData $input
|
||||
* @return $this
|
||||
* @return self|Inputfield
|
||||
*
|
||||
*/
|
||||
public function ___processInput(WireInputData $input) {
|
||||
@@ -175,6 +175,7 @@ class InputfieldTextarea extends InputfieldText {
|
||||
$inputfields->remove($inputfields->getChildByName('pattern')); // pattern is not applicable to textarea
|
||||
//if($this->hasFieldtype !== false) $inputfields->remove($inputfields->get('maxlength'));
|
||||
|
||||
/** @var InputfieldInteger $field */
|
||||
$field = $this->modules->get('InputfieldInteger');
|
||||
$field->setAttribute('name', 'rows');
|
||||
$field->label = $this->_('Rows');
|
||||
|
Reference in New Issue
Block a user