From 53612e9489297a73837c143df5b24559b9d99b79 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Mon, 28 Nov 2016 11:04:02 -0500 Subject: [PATCH] Update ProcessField to use more verbose field type names for additional clarity. Also a couple minor cosmetic adjustments in LanguageSupport --- wire/core/Fieldtype.php | 8 ++++- wire/core/Interfaces.php | 12 +++++++ .../FieldtypeLanguageInterface.php | 14 +-------- .../FieldtypeTextLanguage.module | 18 +++++++++-- .../LanguagesPageFieldValue.php | 2 ++ .../Process/ProcessField/ProcessField.module | 31 +++++++++++++------ 6 files changed, 59 insertions(+), 26 deletions(-) diff --git a/wire/core/Fieldtype.php b/wire/core/Fieldtype.php index 98f48d3c..3202fa4a 100644 --- a/wire/core/Fieldtype.php +++ b/wire/core/Fieldtype.php @@ -51,6 +51,7 @@ * @property bool $_exportMode True when Fieldtype is exporting config data, false otherwise. #pw-internal * @property string $name Name of Fieldtype module. #pw-group-other * @property string $shortName Short name of Fieldtype, which excludes the "Fieldtype" prefix. #pw-group-other + * @property string $longName Long name of Fieldtype, which is typically the module title. #pw-group-other * */ abstract class Fieldtype extends WireData implements Module { @@ -1257,7 +1258,12 @@ abstract class Fieldtype extends WireData implements Module { */ public function get($key) { if($key == 'name') return $this->className(); - if($key == 'shortName') return str_replace('Fieldtype', '', $this->className()); + if($key == 'shortName') { + return str_replace('Fieldtype', '', $this->className()); + } else if($key == 'longName') { + $info = $this->getModuleInfo($this); + return $info['title']; + } return parent::get($key); } diff --git a/wire/core/Interfaces.php b/wire/core/Interfaces.php index e732e6d2..01e5e792 100644 --- a/wire/core/Interfaces.php +++ b/wire/core/Interfaces.php @@ -443,6 +443,18 @@ interface LanguagesValueInterface { } +/** + * Interface used to indicate that the Fieldtype supports multiple languages + * + */ +interface FieldtypeLanguageInterface { + /* + * This interface is symbolic only and doesn't require any additional methods, + * however you do need to add an 'implements FieldtypeLanguageInterface' when defining your class. + * + */ +} + /** * Interface for tracking runtime events * diff --git a/wire/modules/LanguageSupport/FieldtypeLanguageInterface.php b/wire/modules/LanguageSupport/FieldtypeLanguageInterface.php index a98e266b..8f056a79 100644 --- a/wire/modules/LanguageSupport/FieldtypeLanguageInterface.php +++ b/wire/modules/LanguageSupport/FieldtypeLanguageInterface.php @@ -1,16 +1,4 @@ wire('modules')->get('LanguageSupport'); + $maxIndex = (int) $this->wire('database')->getMaxIndexLength(); // note that we use otherLanguagePageIDs rather than wire('languages') because // it's possible that this method may be called before the languages are known foreach($languageSupport->otherLanguagePageIDs as $languageID) { // $schema['data' . $languageID] = $schema['data']; $schema['data' . $languageID] = 'text'; - $schema['keys']["data_exact{$languageID}"] = "KEY `data_exact{$languageID}` (`data{$languageID}`(250))"; + $schema['keys']["data_exact{$languageID}"] = "KEY `data_exact{$languageID}` (`data{$languageID}`($maxIndex))"; $schema['keys']["data{$languageID}"] = "FULLTEXT KEY `data{$languageID}` (`data{$languageID}`)"; } @@ -62,7 +71,12 @@ class FieldtypeTextLanguage extends FieldtypeText implements FieldtypeLanguageIn } /** - * Format value for output, basically typcasting to a string and sending to textformatters from FieldtypeText + * Format value for output, basically typecasting to a string and sending to textformatters from FieldtypeText + * + * @param Page $page + * @param Field $field + * @param LanguagesValueInterface|string $value + * @return string * */ public function formatValue(Page $page, Field $field, $value) { diff --git a/wire/modules/LanguageSupport/LanguagesPageFieldValue.php b/wire/modules/LanguageSupport/LanguagesPageFieldValue.php index f9e283e9..e9c2bc25 100644 --- a/wire/modules/LanguageSupport/LanguagesPageFieldValue.php +++ b/wire/modules/LanguageSupport/LanguagesPageFieldValue.php @@ -51,6 +51,8 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \ /** * Construct the multi language value * + * @param Page $page + * @param Field $field * @param array|string $values * */ diff --git a/wire/modules/Process/ProcessField/ProcessField.module b/wire/modules/Process/ProcessField/ProcessField.module index b51d4a0d..1996539b 100644 --- a/wire/modules/Process/ProcessField/ProcessField.module +++ b/wire/modules/Process/ProcessField/ProcessField.module @@ -210,14 +210,16 @@ class ProcessField extends Process implements ConfigurableModule { $field = $this->modules->get("InputfieldSelect"); $field->attr('id+name', 'fieldtype'); $field->addOption('', $showAllLabel); - foreach($this->fieldtypes as $fieldtype) $field->addOption($fieldtype->name, $fieldtype->shortName); - $this->session->ProcessFieldListFieldtype = $this->sanitizer->name($this->input->get->fieldtype); + foreach($this->fieldtypes as $fieldtype) { + $field->addOption($fieldtype->name, $fieldtype->longName); + } + $this->session->set('ProcessFieldListFieldtype', $this->sanitizer->name($this->input->get('fieldtype'))); $field->label = $this->_('Filter by Field Type'); $field->description = $this->_('When specified, only fields of the selected type will be shown. Built-in fields are also shown when filtering by field type.'); // Filter by fieldtype description - $value = $this->session->ProcessFieldListFieldtype; + $value = $this->session->get('ProcessFieldListFieldtype'); $field->attr('value', $value); if($value && $fieldtype = $this->fieldtypes->get($value)) { - $form->description = sprintf($this->_('Showing fields of type: %s'), $fieldtype->shortName); + $form->description = sprintf($this->_('Showing fields of type: %s'), $fieldtype->longName); $fieldset->collapsed = Inputfield::collapsedNo; } else { $field->collapsed = Inputfield::collapsedYes; @@ -458,7 +460,7 @@ class ProcessField extends Process implements ConfigurableModule { return array( $field->name => "edit?id={$field->id}", $icon . $this->sanitizer->entities($field->getLabel()), - $field->type->shortName, + $this->sanitizer->entities($field->type->longName), "$flagsOut$numTemplates" ); } @@ -1057,12 +1059,21 @@ class ProcessField extends Process implements ConfigurableModule { else $fieldtypes = $this->fieldtypes; if($fieldtypes && count($fieldtypes)) { - foreach($fieldtypes->sort('name') as $fieldtype) { - if(!$this->config->advanced && $fieldtype->isAdvanced() && $this->field->name != 'title' && $field->value != $fieldtype->className()) continue; - $field->addOption($fieldtype->name, $fieldtype->shortName); + $fieldtypeLabels = array(); + foreach($fieldtypes as $fieldtype) { + $label = $fieldtype->longName; + if(isset($fieldtypeLabels[$label])) $label .= " ($fieldtype->name)"; + $fieldtypeLabels[$label] = $fieldtype; + } + ksort($fieldtypeLabels); + $advanced = $this->config->advanced; + foreach($fieldtypeLabels as $label => $fieldtype) { + if(!$advanced && $fieldtype->isAdvanced() && $this->field->name != 'title' + && $field->value != $fieldtype->className()) continue; + $field->addOption($fieldtype->name, $label); } } else { - $field->addOption($this->field->type->name, $this->field->type->shortName); + $field->addOption($this->field->type->name, $this->field->type->longName); } if(!$this->field->id) { @@ -1725,7 +1736,7 @@ class ProcessField extends Process implements ConfigurableModule { $form = $this->modules->get("InputfieldForm"); $form->attr('method', 'post'); $form->attr('action', 'saveChangeType'); - $form->head = sprintf($this->_('Change field type from "%1$s" to "%2$s"'), $this->field->type->shortName, $newType->shortName); + $form->head = sprintf($this->_('Change field type from "%1$s" to "%2$s"'), $this->field->type->longName, $newType->longName); $form->description = $this->_("Please note that changing the field type alters the database schema. If the new fieldtype is not compatible with the old, or if it contains a significantly different schema, it is possible for data loss to occur. As a result, you are advised to backup the database before completing a field type change."); // Change field type description $f = $this->modules->get("InputfieldCheckbox");