diff --git a/core/lib/Drupal/Core/Entity/Annotation/FieldType.php b/core/lib/Drupal/Core/Entity/Annotation/FieldType.php index 3ced435..e73ae01 100644 --- a/core/lib/Drupal/Core/Entity/Annotation/FieldType.php +++ b/core/lib/Drupal/Core/Entity/Annotation/FieldType.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Entity\Annotation; use Drupal\Component\Annotation\Plugin; +use Drupal\Core\TypedData\Annotation\DataType; /** * Defines a FieldType annotation object. @@ -17,7 +18,7 @@ * * @Annotation */ -class FieldType extends Plugin { +class FieldType extends DataType { /** * The plugin ID. @@ -110,10 +111,16 @@ class FieldType extends Plugin { /** * A boolean stating that fields of this type cannot be created through the UI. * - * If TRUE, fields of this type can only be created programmatically. + * If TRUE or the field type is not configurable, fields of this type can only + * be created programmatically. * * @var boolean */ public $no_ui = FALSE; + /** + * {@inheritdoc} + */ + public $list_class = '\Drupal\field\Plugin\Type\FieldType\ConfigField'; + } diff --git a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php index 9f9ceb8..f16ec74 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php @@ -25,7 +25,6 @@ class FieldTypePluginManager extends DefaultPluginManager { protected $defaults = array( 'settings' => array(), 'instance_settings' => array(), - 'list_class' => '\Drupal\field\Plugin\Type\FieldType\ConfigField', ); /** diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/LanguageItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/LanguageItem.php deleted file mode 100644 index 68526f5..0000000 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/LanguageItem.php +++ /dev/null @@ -1,109 +0,0 @@ - 'string', - 'label' => t('Language code'), - ); - static::$propertyDefinitions['language'] = array( - 'type' => 'language_reference', - 'label' => t('Language object'), - 'description' => t('The referenced language'), - // The language object is retrieved via the language code. - 'computed' => TRUE, - 'read-only' => FALSE, - ); - } - return static::$propertyDefinitions; - } - - /** - * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). - */ - public function setValue($values, $notify = TRUE) { - // Treat the values as property value of the language property, if no array - // is given as this handles language codes and objects. - if (isset($values) && !is_array($values)) { - // Directly update the property instead of invoking the parent, so that - // the language property can take care of updating the language code - // property. - $this->properties['language']->setValue($values, $notify); - // If notify was FALSE, ensure the value property gets synched. - if (!$notify) { - $this->set('value', $this->properties['language']->getTargetIdentifier(), FALSE); - } - } - else { - // Make sure that the 'language' property gets set as 'value'. - if (isset($values['value']) && !isset($values['language'])) { - $values['language'] = $values['value']; - } - parent::setValue($values, $notify); - } - } - - /** - * {@inheritdoc} - */ - public function applyDefaultValue($notify = TRUE) { - // Default to LANGCODE_NOT_SPECIFIED. - $this->setValue(array('value' => Language::LANGCODE_NOT_SPECIFIED), $notify); - return $this; - } - - /** - * {@inheritdoc} - */ - public function onChange($property_name) { - // Make sure that the value and the language property stay in sync. - if ($property_name == 'value') { - $this->properties['language']->setValue($this->value, FALSE); - } - elseif ($property_name == 'language') { - $this->set('value', $this->properties['language']->getTargetIdentifier(), FALSE); - } - parent::onChange($property_name); - } -} diff --git a/core/lib/Drupal/Core/Entity/Plugin/field/field_type/LanguageItem.php b/core/lib/Drupal/Core/Entity/Plugin/field/field_type/LanguageItem.php new file mode 100644 index 0000000..4b7ffbe --- /dev/null +++ b/core/lib/Drupal/Core/Entity/Plugin/field/field_type/LanguageItem.php @@ -0,0 +1,111 @@ + 'string', + 'label' => t('Language code'), + ); + static::$propertyDefinitions['language'] = array( + 'type' => 'language_reference', + 'label' => t('Language object'), + 'description' => t('The referenced language'), + // The language object is retrieved via the language code. + 'computed' => TRUE, + 'read-only' => FALSE, + ); + } + return static::$propertyDefinitions; + } + + /** + * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). + */ + public function setValue($values, $notify = TRUE) { + // Treat the values as property value of the language property, if no array + // is given as this handles language codes and objects. + if (isset($values) && !is_array($values)) { + // Directly update the property instead of invoking the parent, so that + // the language property can take care of updating the language code + // property. + $this->properties['language']->setValue($values, $notify); + // If notify was FALSE, ensure the value property gets synched. + if (!$notify) { + $this->set('value', $this->properties['language']->getTargetIdentifier(), FALSE); + } + } + else { + // Make sure that the 'language' property gets set as 'value'. + if (isset($values['value']) && !isset($values['language'])) { + $values['language'] = $values['value']; + } + parent::setValue($values, $notify); + } + } + + /** + * {@inheritdoc} + */ + public function applyDefaultValue($notify = TRUE) { + // Default to LANGCODE_NOT_SPECIFIED. + $this->setValue(array('value' => Language::LANGCODE_NOT_SPECIFIED), $notify); + return $this; + } + + /** + * {@inheritdoc} + */ + public function onChange($property_name) { + // Make sure that the value and the language property stay in sync. + if ($property_name == 'value') { + $this->properties['language']->setValue($this->value, FALSE); + } + elseif ($property_name == 'language') { + $this->set('value', $this->properties['language']->getTargetIdentifier(), FALSE); + } + parent::onChange($property_name); + } +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/FeedStorageController.php b/core/modules/aggregator/lib/Drupal/aggregator/FeedStorageController.php index 36d87eb..5941afe 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/FeedStorageController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedStorageController.php @@ -45,7 +45,7 @@ public function baseFieldDefinitions() { $fields['langcode'] = array( 'label' => t('Language code'), 'description' => t('The feed language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $fields['url'] = array( 'label' => t('URL'), diff --git a/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php b/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php index 016e8ae..bad917e 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php @@ -50,7 +50,7 @@ public function baseFieldDefinitions() { $fields['langcode'] = array( 'label' => t('Language code'), 'description' => t('The feed item language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $fields['link'] = array( 'label' => t('Link'), diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockStorageController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockStorageController.php index 0698234..582b2c6 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockStorageController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockStorageController.php @@ -59,7 +59,7 @@ public function baseFieldDefinitions() { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The comment language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['info'] = array( 'label' => t('Subject'), diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 8cd1a53..ed9f2ea 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -131,7 +131,7 @@ public function baseFieldDefinitions() { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The comment language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['subject'] = array( 'label' => t('Subject'), diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index 7018f94..ad7630f 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -180,7 +180,7 @@ function field_info_field_types($field_type = NULL) { } else { return array_filter(Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions(), function ($definition) { - return $definition->configurable; + return $definition['configurable']; }); } } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/LegacyFieldTypeDiscoveryDecorator.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/LegacyFieldTypeDiscoveryDecorator.php index 9aa6ab7..e1c226f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/LegacyFieldTypeDiscoveryDecorator.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/LegacyFieldTypeDiscoveryDecorator.php @@ -64,6 +64,7 @@ public function getDefinitions() { foreach ($function() as $plugin_id => $definition) { $definition['id'] = $plugin_id; $definition['module'] = $module; + $definition['configurable'] = TRUE; $definition['list_class'] = '\Drupal\field\Plugin\field\field_type\LegacyConfigField'; $definitions[$plugin_id] = $definition; } diff --git a/core/modules/file/lib/Drupal/file/FileStorageController.php b/core/modules/file/lib/Drupal/file/FileStorageController.php index 10ba8d3..1b4836b 100644 --- a/core/modules/file/lib/Drupal/file/FileStorageController.php +++ b/core/modules/file/lib/Drupal/file/FileStorageController.php @@ -58,7 +58,7 @@ public function baseFieldDefinitions() { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The file language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['uid'] = array( 'label' => t('User ID'), diff --git a/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php index c3ccc3c..7da6a17 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -149,7 +149,7 @@ public function baseFieldDefinitions() { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The node language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['title'] = array( 'label' => t('Title'), diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php index be93b68..a6de832 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php @@ -45,7 +45,7 @@ public function baseFieldDefinitions() { $fields['langcode'] = array( 'label' => t('Language code'), 'description' => t('The language code of the test entity.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $fields['name'] = array( 'label' => t('Name'), diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php index cb0821c..7c6103c 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php @@ -81,7 +81,7 @@ public function baseFieldDefinitions() { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The term language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['name'] = array( 'label' => t('Name'), diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index 05961e1..e007277 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -190,17 +190,17 @@ public function baseFieldDefinitions() { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The user language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['preferred_langcode'] = array( 'label' => t('Language code'), 'description' => t("The user's preferred langcode for receiving emails and viewing the site."), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['preferred_admin_langcode'] = array( 'label' => t('Language code'), 'description' => t("The user's preferred langcode for viewing administration pages."), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['name'] = array( 'label' => t('Name'),