Commit b907c2f3 authored by webchick's avatar webchick

Issue #2191709 by andypost, Berdir: Remove the configurable flag on field types.

parent d38a69e1
...@@ -166,7 +166,7 @@ protected function loadFieldItems(array $entities) { ...@@ -166,7 +166,7 @@ protected function loadFieldItems(array $entities) {
foreach ($entity->getTranslationLanguages() as $langcode => $language) { foreach ($entity->getTranslationLanguages() as $langcode => $language) {
$translation = $entity->getTranslation($langcode); $translation = $entity->getTranslation($langcode);
foreach ($translation as $field_name => $items) { foreach ($translation as $field_name => $items) {
if ($items->getFieldDefinition()->isConfigurable() && !$items->isEmpty()) { if ($items->getFieldDefinition() instanceof FieldInstanceConfigInterface && !$items->isEmpty()) {
foreach ($items as $delta => $item) { foreach ($items as $delta => $item) {
// If the field item needs to prepare the cache data, call the // If the field item needs to prepare the cache data, call the
// corresponding method, otherwise use the values as cache // corresponding method, otherwise use the values as cache
......
...@@ -100,13 +100,6 @@ class FieldType extends DataType { ...@@ -100,13 +100,6 @@ class FieldType extends DataType {
*/ */
public $default_formatter; public $default_formatter;
/**
* A boolean stating that fields of this type are configurable.
*
* @var boolean
*/
public $configurable = TRUE;
/** /**
* A boolean stating that fields of this type cannot be created through the UI. * A boolean stating that fields of this type cannot be created through the UI.
* *
......
...@@ -303,13 +303,6 @@ public function isDisplayConfigurable($display_context) { ...@@ -303,13 +303,6 @@ public function isDisplayConfigurable($display_context) {
return isset($this->definition['display'][$display_context]['configurable']) ? $this->definition['display'][$display_context]['configurable'] : FALSE; return isset($this->definition['display'][$display_context]['configurable']) ? $this->definition['display'][$display_context]['configurable'] : FALSE;
} }
/**
* {@inheritdoc}
*/
public function isConfigurable() {
return FALSE;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -111,14 +111,6 @@ public function getSetting($setting_name); ...@@ -111,14 +111,6 @@ public function getSetting($setting_name);
*/ */
public function isTranslatable(); public function isTranslatable();
/**
* Returns whether the field is configurable via field.module.
*
* @return bool
* TRUE if the field is configurable.
*/
public function isConfigurable();
/** /**
* Returns whether the display for the field can be configured. * Returns whether the display for the field can be configured.
* *
......
...@@ -73,10 +73,10 @@ public function getDefaultInstanceSettings($type) { ...@@ -73,10 +73,10 @@ public function getDefaultInstanceSettings($type) {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getConfigurableDefinitions() { public function getUiDefinitions() {
$definitions = $this->getDefinitions(); $definitions = $this->getDefinitions();
return array_filter($definitions, function ($definition) { return array_filter($definitions, function ($definition) {
return $definition['configurable']; return empty($definition['no_ui']) && !empty($definition['default_formatter']) && !empty($definition['default_widget']);
}); });
} }
......
...@@ -39,11 +39,11 @@ public function getDefaultInstanceSettings($type); ...@@ -39,11 +39,11 @@ public function getDefaultInstanceSettings($type);
public function getDefaultSettings($type); public function getDefaultSettings($type);
/** /**
* Gets the definition of all field types that are configurable. * Gets the definition of all field types that can be added via UI.
* *
* @return array * @return array
* An array of field type definitions. * An array of field type definitions.
*/ */
public function getConfigurableDefinitions(); public function getUiDefinitions();
} }
...@@ -95,8 +95,8 @@ public function createInstance($plugin_id, array $configuration = array()) { ...@@ -95,8 +95,8 @@ public function createInstance($plugin_id, array $configuration = array()) {
* - settings: (array) Settings specific to the formatter. Each setting * - settings: (array) Settings specific to the formatter. Each setting
* defaults to the default value specified in the formatter definition. * defaults to the default value specified in the formatter definition.
* *
* @return \Drupal\Core\Field\FormatterInterface * @return \Drupal\Core\Field\FormatterInterface|null
* A formatter object. * A formatter object or NULL when plugin is not found.
*/ */
public function getInstance(array $options) { public function getInstance(array $options) {
$configuration = $options['configuration']; $configuration = $options['configuration'];
...@@ -117,6 +117,9 @@ public function getInstance(array $options) { ...@@ -117,6 +117,9 @@ public function getInstance(array $options) {
if (!isset($definition['class']) || !in_array($field_type, $definition['field_types'])) { if (!isset($definition['class']) || !in_array($field_type, $definition['field_types'])) {
// Grab the default widget for the field type. // Grab the default widget for the field type.
$field_type_definition = $this->fieldTypeManager->getDefinition($field_type); $field_type_definition = $this->fieldTypeManager->getDefinition($field_type);
if (empty($field_type_definition['default_formatter'])) {
return NULL;
}
$plugin_id = $field_type_definition['default_formatter']; $plugin_id = $field_type_definition['default_formatter'];
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* id = "boolean", * id = "boolean",
* label = @Translation("Boolean"), * label = @Translation("Boolean"),
* description = @Translation("An entity field containing a boolean value."), * description = @Translation("An entity field containing a boolean value."),
* configurable = FALSE * no_ui = TRUE
* ) * )
*/ */
class BooleanItem extends FieldItemBase { class BooleanItem extends FieldItemBase {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* id = "date", * id = "date",
* label = @Translation("Date"), * label = @Translation("Date"),
* description = @Translation("An entity field containing a date value."), * description = @Translation("An entity field containing a date value."),
* configurable = FALSE * no_ui = TRUE
* ) * )
*/ */
class DateItem extends FieldItemBase { class DateItem extends FieldItemBase {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,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."),
* configurable = FALSE, * no_ui = TRUE,
* constraints = {"ValidReference" = {}} * constraints = {"ValidReference" = {}}
* ) * )
*/ */
...@@ -225,4 +225,5 @@ public function preSave() { ...@@ -225,4 +225,5 @@ public function preSave() {
public function hasUnsavedEntity() { public function hasUnsavedEntity() {
return $this->target_id === NULL && ($entity = $this->entity) && $entity->isNew(); return $this->target_id === NULL && ($entity = $this->entity) && $entity->isNew();
} }
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* id = "language", * id = "language",
* label = @Translation("Language"), * label = @Translation("Language"),
* description = @Translation("An entity field referencing a language."), * description = @Translation("An entity field referencing a language."),
* configurable = FALSE, * no_ui = TRUE,
* constraints = { * constraints = {
* "ComplexData" = { * "ComplexData" = {
* "value" = {"Length" = {"max" = 12}} * "value" = {"Length" = {"max" = 12}}
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* id = "map", * id = "map",
* label = @Translation("Map"), * label = @Translation("Map"),
* description = @Translation("An entity field for storing a serialized array of values."), * description = @Translation("An entity field for storing a serialized array of values."),
* configurable = FALSE * no_ui = TRUE
* ) * )
*/ */
class MapItem extends FieldItemBase { class MapItem extends FieldItemBase {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* settings = { * settings = {
* "max_length" = "255" * "max_length" = "255"
* }, * },
* configurable = FALSE, * no_ui = TRUE,
* default_widget = "string", * default_widget = "string",
* default_formatter = "string" * default_formatter = "string"
* ) * )
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* id = "string_long", * id = "string_long",
* label = @Translation("Long string"), * label = @Translation("Long string"),
* description = @Translation("An entity field containing a long string value."), * description = @Translation("An entity field containing a long string value."),
* configurable = FALSE * no_ui = FALSE
* ) * )
*/ */
class StringLongItem extends StringItem { class StringLongItem extends StringItem {
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
* settings = { * settings = {
* "max_length" = "2048" * "max_length" = "2048"
* }, * },
* configurable = FALSE * no_ui = TRUE
* ) * )
*/ */
class UriItem extends StringItem { class UriItem extends StringItem {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* settings = { * settings = {
* "max_length" = "128" * "max_length" = "128"
* }, * },
* configurable = FALSE * no_ui = TRUE
* ) * )
*/ */
class UuidItem extends StringItem { class UuidItem extends StringItem {
......
...@@ -75,8 +75,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac ...@@ -75,8 +75,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
* - settings: (array) Settings specific to the widget. Each setting * - settings: (array) Settings specific to the widget. Each setting
* defaults to the default value specified in the widget definition. * defaults to the default value specified in the widget definition.
* *
* @return \Drupal\Core\Field\WidgetInterface * @return \Drupal\Core\Field\WidgetInterface|null
* A Widget object. * A Widget object or NULL when plugin is not found.
*/ */
public function getInstance(array $options) { public function getInstance(array $options) {
// Fill in defaults for missing properties. // Fill in defaults for missing properties.
...@@ -103,6 +103,9 @@ public function getInstance(array $options) { ...@@ -103,6 +103,9 @@ public function getInstance(array $options) {
if (!isset($definition['class']) || !in_array($field_type, $definition['field_types'])) { if (!isset($definition['class']) || !in_array($field_type, $definition['field_types'])) {
// Grab the default widget for the field type. // Grab the default widget for the field type.
$field_type_definition = $this->fieldTypeManager->getDefinition($field_type); $field_type_definition = $this->fieldTypeManager->getDefinition($field_type);
if (empty($field_type_definition['default_widget'])) {
return NULL;
}
$plugin_id = $field_type_definition['default_widget']; $plugin_id = $field_type_definition['default_widget'];
} }
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
*/ */
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\field\Field as FieldService; use Drupal\field\Field as FieldService;
use Drupal\field\FieldInstanceConfigInterface;
/** /**
* Returns a form element to configure field synchronization. * Returns a form element to configure field synchronization.
...@@ -102,14 +102,13 @@ function _content_translation_form_language_content_settings_form_alter(array &$ ...@@ -102,14 +102,13 @@ function _content_translation_form_language_content_settings_form_alter(array &$
// translation. // translation.
// @todo Remove this special casing as soon as configurable and // @todo Remove this special casing as soon as configurable and
// base field definitions are "unified". // base field definitions are "unified".
if ($definition->isConfigurable() && ($field = FieldService::fieldInfo()->getField($entity_type_id, $field_name))) { if ($definition instanceof FieldInstanceConfigInterface) {
$instance = FieldService::fieldInfo()->getInstance($entity_type_id, $bundle, $field_name);
$form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array( $form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array(
'#label' => $instance->getLabel(), '#label' => $definition->getLabel(),
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => $translatable, '#default_value' => $translatable,
); );
$column_element = content_translation_field_sync_widget($instance); $column_element = content_translation_field_sync_widget($definition);
if ($column_element) { if ($column_element) {
$form['settings'][$entity_type_id][$bundle]['columns'][$field_name] = $column_element; $form['settings'][$entity_type_id][$bundle]['columns'][$field_name] = $column_element;
......
...@@ -40,7 +40,7 @@ function entity_reference_help($path, $arg) { ...@@ -40,7 +40,7 @@ function entity_reference_help($path, $arg) {
*/ */
function entity_reference_field_info_alter(&$info) { function entity_reference_field_info_alter(&$info) {
// Make the entity reference field configurable. // Make the entity reference field configurable.
$info['entity_reference']['configurable'] = TRUE; $info['entity_reference']['no_ui'] = FALSE;
$info['entity_reference']['class'] = '\Drupal\entity_reference\ConfigurableEntityReferenceItem'; $info['entity_reference']['class'] = '\Drupal\entity_reference\ConfigurableEntityReferenceItem';
$info['entity_reference']['list_class'] = '\Drupal\entity_reference\Plugin\Field\FieldType\ConfigurableEntityReferenceFieldItemList'; $info['entity_reference']['list_class'] = '\Drupal\entity_reference\Plugin\Field\FieldType\ConfigurableEntityReferenceFieldItemList';
$info['entity_reference']['settings']['target_type'] = \Drupal::moduleHandler()->moduleExists('node') ? 'node' : 'user'; $info['entity_reference']['settings']['target_type'] = \Drupal::moduleHandler()->moduleExists('node') ? 'node' : 'user';
......
...@@ -335,8 +335,7 @@ function field_attach_form(EntityInterface $entity, &$form, &$form_state, $langc ...@@ -335,8 +335,7 @@ function field_attach_form(EntityInterface $entity, &$form, &$form_state, $langc
function field_attach_form_validate(ContentEntityInterface $entity, $form, &$form_state, array $options = array()) { function field_attach_form_validate(ContentEntityInterface $entity, $form, &$form_state, array $options = array()) {
$has_violations = FALSE; $has_violations = FALSE;
foreach ($entity as $field_name => $field) { foreach ($entity as $field_name => $field) {
$definition = $field->getFieldDefinition(); if (empty($options['field_name']) || $options['field_name'] == $field_name) {
if ($definition->isConfigurable() && (empty($options['field_name']) || $options['field_name'] == $field_name)) {
$field_violations = $field->validate(); $field_violations = $field->validate();
if (count($field_violations)) { if (count($field_violations)) {
$has_violations = TRUE; $has_violations = TRUE;
......
...@@ -97,7 +97,7 @@ function field_help($path, $arg) { ...@@ -97,7 +97,7 @@ function field_help($path, $arg) {
$items = array(); $items = array();
$info = system_get_info('module'); $info = system_get_info('module');
$field_widgets = \Drupal::service('plugin.manager.field.widget')->getDefinitions(); $field_widgets = \Drupal::service('plugin.manager.field.widget')->getDefinitions();
$field_types = \Drupal::service('plugin.manager.field.field_type')->getConfigurableDefinitions(); $field_types = \Drupal::service('plugin.manager.field.field_type')->getUiDefinitions();
$providers = array(); $providers = array();
foreach (array_merge($field_types, $field_widgets) as $plugin) { foreach (array_merge($field_types, $field_widgets) as $plugin) {
$providers[] = $plugin['provider']; $providers[] = $plugin['provider'];
......
...@@ -621,13 +621,6 @@ public function isLocked() { ...@@ -621,13 +621,6 @@ public function isLocked() {
*/ */
public function getDefaultValue(EntityInterface $entity) { } public function getDefaultValue(EntityInterface $entity) { }
/**
* {@inheritdoc}
*/
public function isConfigurable() {
return TRUE;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -577,13 +577,6 @@ public function getDefaultValue(EntityInterface $entity) { ...@@ -577,13 +577,6 @@ public function getDefaultValue(EntityInterface $entity) {
} }
} }
/**
* {@inheritdoc}
*/
public function isConfigurable() {
return TRUE;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -26,7 +26,7 @@ function testFieldInfo() { ...@@ -26,7 +26,7 @@ function testFieldInfo() {
// Test that field_test module's fields, widgets, and formatters show up. // Test that field_test module's fields, widgets, and formatters show up.
$field_test_info = $this->getExpectedFieldTypeDefinition(); $field_test_info = $this->getExpectedFieldTypeDefinition();
$entity_type = \Drupal::service('plugin.manager.field.field_type')->getConfigurableDefinitions(); $entity_type = \Drupal::service('plugin.manager.field.field_type')->getDefinitions();
foreach ($field_test_info as $t_key => $field_type) { foreach ($field_test_info as $t_key => $field_type) {
foreach ($field_type as $key => $val) { foreach ($field_type as $key => $val) {
$this->assertEqual($entity_type[$t_key][$key], $val, format_string('Field type %t_key key %key is %value', array('%t_key' => $t_key, '%key' => $key, '%value' => print_r($val, TRUE)))); $this->assertEqual($entity_type[$t_key][$key], $val, format_string('Field type %t_key key %key is %value', array('%t_key' => $t_key, '%key' => $key, '%value' => print_r($val, TRUE))));
......
...@@ -169,7 +169,7 @@ protected function getPluginOptions($field_type) { ...@@ -169,7 +169,7 @@ protected function getPluginOptions($field_type) {
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getDefaultPlugin($field_type) { protected function getDefaultPlugin($field_type) {
return $this->fieldTypes[$field_type]['default_formatter']; return isset($this->fieldTypes[$field_type]['default_formatter']) ? $this->fieldTypes[$field_type]['default_formatter'] : NULL;
} }
/** /**
......
...@@ -66,7 +66,7 @@ public function __construct(EntityTypeInterface $entity_type, EntityManagerInter ...@@ -66,7 +66,7 @@ public function __construct(EntityTypeInterface $entity_type, EntityManagerInter
$this->entityManager = $entity_manager; $this->entityManager = $entity_manager;
$this->bundles = entity_get_bundles(); $this->bundles = entity_get_bundles();
$this->fieldTypeManager = $field_type_manager; $this->fieldTypeManager = $field_type_manager;
$this->fieldTypes = $this->fieldTypeManager->getConfigurableDefinitions(); $this->fieldTypes = $this->fieldTypeManager->getDefinitions();
} }
/** /**
......
...@@ -89,7 +89,7 @@ public function buildForm(array $form, array &$form_state, $entity_type_id = NUL ...@@ -89,7 +89,7 @@ public function buildForm(array $form, array &$form_state, $entity_type_id = NUL
// Gather bundle information. // Gather bundle information.
$instances = field_info_instances($this->entity_type, $this->bundle); $instances = field_info_instances($this->entity_type, $this->bundle);
$field_types = $this->fieldTypeManager->getConfigurableDefinitions(); $field_types = $this->fieldTypeManager->getDefinitions();
// Field prefix. // Field prefix.
$field_prefix = \Drupal::config('field_ui.settings')->get('field_prefix'); $field_prefix = \Drupal::config('field_ui.settings')->get('field_prefix');
......
...@@ -136,7 +136,7 @@ protected function getPluginOptions($field_type) { ...@@ -136,7 +136,7 @@ protected function getPluginOptions($field_type) {
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getDefaultPlugin($field_type) { protected function getDefaultPlugin($field_type) {
return $this->fieldTypes[$field_type]['default_widget']; return isset($this->fieldTypes[$field_type]['default_widget']) ? $this->fieldTypes[$field_type]['default_widget'] : NULL;
} }
/** /**
......
...@@ -489,7 +489,7 @@ function testHiddenFields() { ...@@ -489,7 +489,7 @@ function testHiddenFields() {
// Check that non-configurable fields are not available. // Check that non-configurable fields are not available.
$field_types = \Drupal::service('plugin.manager.field.field_type')->getDefinitions(); $field_types = \Drupal::service('plugin.manager.field.field_type')->getDefinitions();
foreach ($field_types as $field_type => $definition) { foreach ($field_types as $field_type => $definition) {
if ($definition['configurable'] && empty($definition['no_ui'])) { if (empty($definition['no_ui'])) {
$this->assertTrue($this->xpath('//select[@id="edit-fields-add-new-field-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), String::format('Configurable field type @field_type is available.', array('@field_type' => $field_type))); $this->assertTrue($this->xpath('//select[@id="edit-fields-add-new-field-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), String::format('Configurable field type @field_type is available.', array('@field_type' => $field_type)));
} }
else { else {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* id = "path", * id = "path",
* label = @Translation("Path"), * label = @Translation("Path"),
* description = @Translation("An entity field containing a path alias and related data."), * description = @Translation("An entity field containing a path alias and related data."),
* configurable = FALSE * no_ui = TRUE
* ) * )
*/ */
class PathItem extends FieldItemBase { class PathItem extends FieldItemBase {
......
...@@ -194,12 +194,4 @@ public function testFieldRequired() { ...@@ -194,12 +194,4 @@ public function testFieldRequired() {
$this->assertFalse($definition->isRequired()); $this->assertFalse($definition->isRequired());
} }
/**
* Tests configurable.
*/
public function testFieldConfigurable() {
$definition = FieldDefinition::create($this->fieldType);
$this->assertFalse($definition->isConfigurable());
}
} }
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