Commit b907c2f3 authored by webchick's avatar webchick
Browse files

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

parent d38a69e1
......@@ -166,7 +166,7 @@ protected function loadFieldItems(array $entities) {
foreach ($entity->getTranslationLanguages() as $langcode => $language) {
$translation = $entity->getTranslation($langcode);
foreach ($translation as $field_name => $items) {
if ($items->getFieldDefinition()->isConfigurable() && !$items->isEmpty()) {
if ($items->getFieldDefinition() instanceof FieldInstanceConfigInterface && !$items->isEmpty()) {
foreach ($items as $delta => $item) {
// If the field item needs to prepare the cache data, call the
// corresponding method, otherwise use the values as cache
......
......@@ -100,13 +100,6 @@ class FieldType extends DataType {
*/
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.
*
......
......@@ -303,13 +303,6 @@ public function isDisplayConfigurable($display_context) {
return isset($this->definition['display'][$display_context]['configurable']) ? $this->definition['display'][$display_context]['configurable'] : FALSE;
}
/**
* {@inheritdoc}
*/
public function isConfigurable() {
return FALSE;
}
/**
* {@inheritdoc}
*/
......
......@@ -111,14 +111,6 @@ public function getSetting($setting_name);
*/
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.
*
......
......@@ -73,10 +73,10 @@ public function getDefaultInstanceSettings($type) {
/**
* {@inheritdoc}
*/
public function getConfigurableDefinitions() {
public function getUiDefinitions() {
$definitions = $this->getDefinitions();
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);
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
* An array of field type definitions.
*/
public function getConfigurableDefinitions();
public function getUiDefinitions();
}
......@@ -95,8 +95,8 @@ public function createInstance($plugin_id, array $configuration = array()) {
* - settings: (array) Settings specific to the formatter. Each setting
* defaults to the default value specified in the formatter definition.
*
* @return \Drupal\Core\Field\FormatterInterface
* A formatter object.
* @return \Drupal\Core\Field\FormatterInterface|null
* A formatter object or NULL when plugin is not found.
*/
public function getInstance(array $options) {
$configuration = $options['configuration'];
......@@ -117,6 +117,9 @@ public function getInstance(array $options) {
if (!isset($definition['class']) || !in_array($field_type, $definition['field_types'])) {
// Grab the default widget for the 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'];
}
......
......@@ -18,7 +18,7 @@
* id = "boolean",
* label = @Translation("Boolean"),
* description = @Translation("An entity field containing a boolean value."),
* configurable = FALSE
* no_ui = TRUE
* )
*/
class BooleanItem extends FieldItemBase {
......
......@@ -18,7 +18,7 @@
* id = "date",
* label = @Translation("Date"),
* description = @Translation("An entity field containing a date value."),
* configurable = FALSE
* no_ui = TRUE
* )
*/
class DateItem extends FieldItemBase {
......
......@@ -26,7 +26,7 @@
* id = "entity_reference",
* label = @Translation("Entity reference"),
* description = @Translation("An entity field containing an entity reference."),
* configurable = FALSE,
* no_ui = TRUE,
* constraints = {"ValidReference" = {}}
* )
*/
......@@ -225,4 +225,5 @@ public function preSave() {
public function hasUnsavedEntity() {
return $this->target_id === NULL && ($entity = $this->entity) && $entity->isNew();
}
}
......@@ -20,7 +20,7 @@
* id = "language",
* label = @Translation("Language"),
* description = @Translation("An entity field referencing a language."),
* configurable = FALSE,
* no_ui = TRUE,
* constraints = {
* "ComplexData" = {
* "value" = {"Length" = {"max" = 12}}
......
......@@ -18,7 +18,7 @@
* id = "map",
* label = @Translation("Map"),
* description = @Translation("An entity field for storing a serialized array of values."),
* configurable = FALSE
* no_ui = TRUE
* )
*/
class MapItem extends FieldItemBase {
......
......@@ -21,7 +21,7 @@
* settings = {
* "max_length" = "255"
* },
* configurable = FALSE,
* no_ui = TRUE,
* default_widget = "string",
* default_formatter = "string"
* )
......
......@@ -16,7 +16,7 @@
* id = "string_long",
* label = @Translation("Long string"),
* description = @Translation("An entity field containing a long string value."),
* configurable = FALSE
* no_ui = FALSE
* )
*/
class StringLongItem extends StringItem {
......
......@@ -24,7 +24,7 @@
* settings = {
* "max_length" = "2048"
* },
* configurable = FALSE
* no_ui = TRUE
* )
*/
class UriItem extends StringItem {
......
......@@ -19,7 +19,7 @@
* settings = {
* "max_length" = "128"
* },
* configurable = FALSE
* no_ui = TRUE
* )
*/
class UuidItem extends StringItem {
......
......@@ -75,8 +75,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
* - settings: (array) Settings specific to the widget. Each setting
* defaults to the default value specified in the widget definition.
*
* @return \Drupal\Core\Field\WidgetInterface
* A Widget object.
* @return \Drupal\Core\Field\WidgetInterface|null
* A Widget object or NULL when plugin is not found.
*/
public function getInstance(array $options) {
// Fill in defaults for missing properties.
......@@ -103,6 +103,9 @@ public function getInstance(array $options) {
if (!isset($definition['class']) || !in_array($field_type, $definition['field_types'])) {
// Grab the default widget for the 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'];
}
......
......@@ -6,10 +6,10 @@
*/
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Language\Language;
use Drupal\field\Field as FieldService;
use Drupal\field\FieldInstanceConfigInterface;
/**
* Returns a form element to configure field synchronization.
......@@ -102,14 +102,13 @@ function _content_translation_form_language_content_settings_form_alter(array &$
// translation.
// @todo Remove this special casing as soon as configurable and
// base field definitions are "unified".
if ($definition->isConfigurable() && ($field = FieldService::fieldInfo()->getField($entity_type_id, $field_name))) {
$instance = FieldService::fieldInfo()->getInstance($entity_type_id, $bundle, $field_name);
if ($definition instanceof FieldInstanceConfigInterface) {
$form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array(
'#label' => $instance->getLabel(),
'#label' => $definition->getLabel(),
'#type' => 'checkbox',
'#default_value' => $translatable,
);
$column_element = content_translation_field_sync_widget($instance);
$column_element = content_translation_field_sync_widget($definition);
if ($column_element) {
$form['settings'][$entity_type_id][$bundle]['columns'][$field_name] = $column_element;
......
......@@ -40,7 +40,7 @@ function entity_reference_help($path, $arg) {
*/
function entity_reference_field_info_alter(&$info) {
// 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']['list_class'] = '\Drupal\entity_reference\Plugin\Field\FieldType\ConfigurableEntityReferenceFieldItemList';
$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
function field_attach_form_validate(ContentEntityInterface $entity, $form, &$form_state, array $options = array()) {
$has_violations = FALSE;
foreach ($entity as $field_name => $field) {
$definition = $field->getFieldDefinition();
if ($definition->isConfigurable() && (empty($options['field_name']) || $options['field_name'] == $field_name)) {
if (empty($options['field_name']) || $options['field_name'] == $field_name) {
$field_violations = $field->validate();
if (count($field_violations)) {
$has_violations = TRUE;
......
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