Commit 6ba9484c authored by catch's avatar catch

Issue #2373491 by amateescu, jibran: Categorize field type plugins

parent e3003f60
...@@ -53,6 +53,15 @@ class FieldType extends DataType { ...@@ -53,6 +53,15 @@ class FieldType extends DataType {
*/ */
public $description; public $description;
/**
* The category under which the field type should be listed in the UI.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $category = '';
/** /**
* The plugin_id of the default widget for this field type. * The plugin_id of the default widget for this field type.
* *
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\TypedData\TypedDataManager; use Drupal\Core\TypedData\TypedDataManager;
...@@ -21,6 +22,8 @@ ...@@ -21,6 +22,8 @@
*/ */
class FieldTypePluginManager extends DefaultPluginManager implements FieldTypePluginManagerInterface { class FieldTypePluginManager extends DefaultPluginManager implements FieldTypePluginManagerInterface {
use CategorizingPluginManagerTrait;
/** /**
* The typed data manager. * The typed data manager.
* *
...@@ -92,6 +95,11 @@ public function processDefinition(&$definition, $plugin_id) { ...@@ -92,6 +95,11 @@ public function processDefinition(&$definition, $plugin_id) {
if (!isset($definition['list_class'])) { if (!isset($definition['list_class'])) {
$definition['list_class'] = '\Drupal\Core\Field\FieldItemList'; $definition['list_class'] = '\Drupal\Core\Field\FieldItemList';
} }
// Ensure that every field type has a category.
if (empty($definition['category'])) {
$definition['category'] = $this->t('General');
}
} }
/** /**
...@@ -124,7 +132,7 @@ public function getDefaultFieldSettings($type) { ...@@ -124,7 +132,7 @@ public function getDefaultFieldSettings($type) {
public function getUiDefinitions() { public function getUiDefinitions() {
$definitions = $this->getDefinitions(); $definitions = $this->getDefinitions();
return array_filter($definitions, function ($definition) { return array_filter($definitions, function ($definition) {
return empty($definition['no_ui']) && !empty($definition['default_formatter']) && !empty($definition['default_widget']); return empty($definition['no_ui']);
}); });
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace Drupal\Core\Field; namespace Drupal\Core\Field;
use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\FieldableEntityInterface;
...@@ -15,7 +16,7 @@ ...@@ -15,7 +16,7 @@
* *
* @ingroup field_types * @ingroup field_types
*/ */
interface FieldTypePluginManagerInterface extends PluginManagerInterface { interface FieldTypePluginManagerInterface extends PluginManagerInterface, CategorizingPluginManagerInterface {
/** /**
* Creates a new field item list. * Creates a new field item list.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
* id = "decimal", * id = "decimal",
* label = @Translation("Number (decimal)"), * label = @Translation("Number (decimal)"),
* description = @Translation("This field stores a number in the database in a fixed decimal format."), * description = @Translation("This field stores a number in the database in a fixed decimal format."),
* category = @Translation("Number"),
* default_widget = "number", * default_widget = "number",
* default_formatter = "number_decimal" * default_formatter = "number_decimal"
* ) * )
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
* id = "entity_reference", * id = "entity_reference",
* label = @Translation("Entity reference"), * label = @Translation("Entity reference"),
* description = @Translation("An entity field containing an entity reference."), * description = @Translation("An entity field containing an entity reference."),
* category = @Translation("Reference"),
* no_ui = TRUE, * no_ui = TRUE,
* list_class = "\Drupal\Core\Field\EntityReferenceFieldItemList", * list_class = "\Drupal\Core\Field\EntityReferenceFieldItemList",
* constraints = {"ValidReference" = {}} * constraints = {"ValidReference" = {}}
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
* id = "float", * id = "float",
* label = @Translation("Number (float)"), * label = @Translation("Number (float)"),
* description = @Translation("This field stores a number in the database in a floating point format."), * description = @Translation("This field stores a number in the database in a floating point format."),
* category = @Translation("Number"),
* default_widget = "number", * default_widget = "number",
* default_formatter = "number_decimal" * default_formatter = "number_decimal"
* ) * )
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* id = "integer", * id = "integer",
* label = @Translation("Number (integer)"), * label = @Translation("Number (integer)"),
* description = @Translation("This field stores a number in the database as an integer."), * description = @Translation("This field stores a number in the database as an integer."),
* category = @Translation("Number"),
* default_widget = "number", * default_widget = "number",
* default_formatter = "number_integer" * default_formatter = "number_integer"
* ) * )
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
* id = "string", * id = "string",
* label = @Translation("Text (plain)"), * label = @Translation("Text (plain)"),
* description = @Translation("A field containing a plain string value."), * description = @Translation("A field containing a plain string value."),
* category = @Translation("Text"),
* default_widget = "string_textfield", * default_widget = "string_textfield",
* default_formatter = "string" * default_formatter = "string"
* ) * )
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* id = "string_long", * id = "string_long",
* label = @Translation("Text (plain, long)"), * label = @Translation("Text (plain, long)"),
* description = @Translation("A field containing a long string value."), * description = @Translation("A field containing a long string value."),
* category = @Translation("Text"),
* default_widget = "string_textarea", * default_widget = "string_textarea",
* default_formatter = "basic_string", * default_formatter = "basic_string",
* ) * )
......
...@@ -321,7 +321,7 @@ function comment_form_field_ui_field_storage_add_form_alter(&$form, FormStateInt ...@@ -321,7 +321,7 @@ function comment_form_field_ui_field_storage_add_form_alter(&$form, FormStateInt
} }
if (!_comment_entity_uses_integer_id($form_state->get('entity_type_id'))) { if (!_comment_entity_uses_integer_id($form_state->get('entity_type_id'))) {
// You cannot use comment fields on entity types with non-integer IDs. // You cannot use comment fields on entity types with non-integer IDs.
unset($form['add']['new_storage_type']['#options']['comment']); unset($form['add']['new_storage_type']['#options'][t('General')]['comment']);
} }
} }
......
...@@ -119,13 +119,11 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t ...@@ -119,13 +119,11 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
// Gather valid field types. // Gather valid field types.
$field_type_options = array(); $field_type_options = array();
foreach ($this->fieldTypePluginManager->getDefinitions() as $name => $field_type) { foreach ($this->fieldTypePluginManager->getGroupedDefinitions($this->fieldTypePluginManager->getUiDefinitions()) as $category => $field_types) {
// Skip field types which should not be added via user interface. foreach ($field_types as $name => $field_type) {
if (empty($field_type['no_ui'])) { $field_type_options[$category][$name] = $field_type['label'];
$field_type_options[$name] = $field_type['label'];
} }
} }
asort($field_type_options);
$form['add'] = array( $form['add'] = array(
'#type' => 'container', '#type' => 'container',
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* id = "file", * id = "file",
* label = @Translation("File"), * label = @Translation("File"),
* description = @Translation("This field stores the ID of a file as an integer value."), * description = @Translation("This field stores the ID of a file as an integer value."),
* category = @Translation("Reference"),
* default_widget = "file_generic", * default_widget = "file_generic",
* default_formatter = "file_default", * default_formatter = "file_default",
* list_class = "\Drupal\file\Plugin\Field\FieldType\FileFieldItemList", * list_class = "\Drupal\file\Plugin\Field\FieldType\FileFieldItemList",
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* id = "image", * id = "image",
* label = @Translation("Image"), * label = @Translation("Image"),
* description = @Translation("This field stores the ID of an image file as an integer value."), * description = @Translation("This field stores the ID of an image file as an integer value."),
* category = @Translation("Reference"),
* default_widget = "image_image", * default_widget = "image_image",
* default_formatter = "image", * default_formatter = "image",
* column_groups = { * column_groups = {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* id = "list_float", * id = "list_float",
* label = @Translation("List (float)"), * label = @Translation("List (float)"),
* description = @Translation("This field stores float values from a list of allowed 'value => label' pairs, i.e. 'Fraction': 0 => 0, .25 => 1/4, .75 => 3/4, 1 => 1."), * description = @Translation("This field stores float values from a list of allowed 'value => label' pairs, i.e. 'Fraction': 0 => 0, .25 => 1/4, .75 => 3/4, 1 => 1."),
* category = @Translation("Number"),
* default_widget = "options_select", * default_widget = "options_select",
* default_formatter = "list_default", * default_formatter = "list_default",
* ) * )
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* id = "list_integer", * id = "list_integer",
* label = @Translation("List (integer)"), * label = @Translation("List (integer)"),
* description = @Translation("This field stores integer values from a list of allowed 'value => label' pairs, i.e. 'Lifetime in days': 1 => 1 day, 7 => 1 week, 31 => 1 month."), * description = @Translation("This field stores integer values from a list of allowed 'value => label' pairs, i.e. 'Lifetime in days': 1 => 1 day, 7 => 1 week, 31 => 1 month."),
* category = @Translation("Number"),
* default_widget = "options_select", * default_widget = "options_select",
* default_formatter = "list_default", * default_formatter = "list_default",
* ) * )
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* id = "list_string", * id = "list_string",
* label = @Translation("List (text)"), * label = @Translation("List (text)"),
* description = @Translation("This field stores text values from a list of allowed 'value => label' pairs, i.e. 'US States': IL => Illinois, IA => Iowa, IN => Indiana."), * description = @Translation("This field stores text values from a list of allowed 'value => label' pairs, i.e. 'US States': IL => Illinois, IA => Iowa, IN => Indiana."),
* category = @Translation("Text"),
* default_widget = "options_select", * default_widget = "options_select",
* default_formatter = "list_default", * default_formatter = "list_default",
* ) * )
......
...@@ -1127,7 +1127,7 @@ protected function assertNoFieldChecked($id, $message = '', $group = 'Browser') ...@@ -1127,7 +1127,7 @@ protected function assertNoFieldChecked($id, $message = '', $group = 'Browser')
* TRUE on pass, FALSE on fail. * TRUE on pass, FALSE on fail.
*/ */
protected function assertOption($id, $option, $message = '', $group = 'Browser') { protected function assertOption($id, $option, $message = '', $group = 'Browser') {
$options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option)); $options = $this->xpath('//select[@id=:id]//option[@value=:option]', array(':id' => $id, ':option' => $option));
return $this->assertTrue(isset($options[0]), $message ? $message : String::format('Option @option for field @id exists.', array('@option' => $option, '@id' => $id)), $group); return $this->assertTrue(isset($options[0]), $message ? $message : String::format('Option @option for field @id exists.', array('@option' => $option, '@id' => $id)), $group);
} }
...@@ -1153,7 +1153,7 @@ protected function assertOption($id, $option, $message = '', $group = 'Browser') ...@@ -1153,7 +1153,7 @@ protected function assertOption($id, $option, $message = '', $group = 'Browser')
*/ */
protected function assertNoOption($id, $option, $message = '', $group = 'Browser') { protected function assertNoOption($id, $option, $message = '', $group = 'Browser') {
$selects = $this->xpath('//select[@id=:id]', array(':id' => $id)); $selects = $this->xpath('//select[@id=:id]', array(':id' => $id));
$options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option)); $options = $this->xpath('//select[@id=:id]//option[@value=:option]', array(':id' => $id, ':option' => $option));
return $this->assertTrue(isset($selects[0]) && !isset($options[0]), $message ? $message : String::format('Option @option for field @id does not exist.', array('@option' => $option, '@id' => $id)), $group); return $this->assertTrue(isset($selects[0]) && !isset($options[0]), $message ? $message : String::format('Option @option for field @id does not exist.', array('@option' => $option, '@id' => $id)), $group);
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* id = "taxonomy_term_reference", * id = "taxonomy_term_reference",
* label = @Translation("Term Reference"), * label = @Translation("Term Reference"),
* description = @Translation("This field stores a reference to a taxonomy term."), * description = @Translation("This field stores a reference to a taxonomy term."),
* category = @Translation("Reference"),
* default_widget = "options_select", * default_widget = "options_select",
* default_formatter = "taxonomy_term_reference_link", * default_formatter = "taxonomy_term_reference_link",
* list_class = "\Drupal\Core\Field\EntityReferenceFieldItemList", * list_class = "\Drupal\Core\Field\EntityReferenceFieldItemList",
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
* id = "telephone", * id = "telephone",
* label = @Translation("Telephone number"), * label = @Translation("Telephone number"),
* description = @Translation("This field stores a telephone number in the database."), * description = @Translation("This field stores a telephone number in the database."),
* category = @Translation("Number"),
* default_widget = "telephone_default", * default_widget = "telephone_default",
* default_formatter = "basic_string" * default_formatter = "basic_string"
* ) * )
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* id = "text", * id = "text",
* label = @Translation("Text (formatted)"), * label = @Translation("Text (formatted)"),
* description = @Translation("This field stores a text with a text format."), * description = @Translation("This field stores a text with a text format."),
* category = @Translation("Text"),
* default_widget = "text_textfield", * default_widget = "text_textfield",
* default_formatter = "text_default" * default_formatter = "text_default"
* ) * )
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* id = "text_long", * id = "text_long",
* label = @Translation("Text (formatted, long)"), * label = @Translation("Text (formatted, long)"),
* description = @Translation("This field stores a long text with a text format."), * description = @Translation("This field stores a long text with a text format."),
* category = @Translation("Text"),
* default_widget = "text_textarea", * default_widget = "text_textarea",
* default_formatter = "text_default" * default_formatter = "text_default"
* ) * )
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* id = "text_with_summary", * id = "text_with_summary",
* label = @Translation("Text (formatted, long, with summary)"), * label = @Translation("Text (formatted, long, with summary)"),
* description = @Translation("This field stores long text with a format and an optional summary."), * description = @Translation("This field stores long text with a format and an optional summary."),
* category = @Translation("Text"),
* default_widget = "text_textarea_with_summary", * default_widget = "text_textarea_with_summary",
* default_formatter = "text_default" * default_formatter = "text_default"
* ) * )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment