mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 03:05:26 +02:00
Update ProcessField to use more verbose field type names for additional clarity. Also a couple minor cosmetic adjustments in LanguageSupport
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
*
|
||||
|
@@ -1,16 +1,4 @@
|
||||
<?php namespace ProcessWire;
|
||||
|
||||
/**
|
||||
* Interface used to indicate that the Fieldtype supports multiple languages
|
||||
*
|
||||
*/
|
||||
// moved to /wire/core/Interfaces.php
|
||||
|
||||
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.
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
|
@@ -25,6 +25,11 @@ class FieldtypeTextLanguage extends FieldtypeText implements FieldtypeLanguageIn
|
||||
|
||||
/**
|
||||
* Sanitize value for storage
|
||||
*
|
||||
* @param Page $page
|
||||
* @param Field $field
|
||||
* @param LanguagesValueInterface|string $value
|
||||
* @return LanguagesPageFieldValue
|
||||
*
|
||||
*/
|
||||
public function sanitizeValue(Page $page, Field $field, $value) {
|
||||
@@ -42,19 +47,23 @@ class FieldtypeTextLanguage extends FieldtypeText implements FieldtypeLanguageIn
|
||||
|
||||
/**
|
||||
* Return the database schema in specified format
|
||||
*
|
||||
* @param Field $field
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getDatabaseSchema(Field $field) {
|
||||
|
||||
$schema = parent::getDatabaseSchema($field);
|
||||
$languageSupport = $this->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) {
|
||||
|
@@ -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
|
||||
*
|
||||
*/
|
||||
|
@@ -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<a href='$numTemplatesLink'>$numTemplates</a>"
|
||||
);
|
||||
}
|
||||
@@ -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");
|
||||
|
Reference in New Issue
Block a user