Commit 0f8b4e79 authored by alexpott's avatar alexpott

Issue #2023563 by Berdir, smiletrl, fago: Convert entity field types to the field_type plugin.

parent 5b026c38
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\Core\Entity\Annotation; namespace Drupal\Core\Entity\Annotation;
use Drupal\Component\Annotation\Plugin; use Drupal\Core\TypedData\Annotation\DataType;
/** /**
* Defines a FieldType annotation object. * Defines a FieldType annotation object.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* *
* @Annotation * @Annotation
*/ */
class FieldType extends Plugin { class FieldType extends DataType {
/** /**
* The plugin ID. * The plugin ID.
...@@ -103,8 +103,6 @@ class FieldType extends Plugin { ...@@ -103,8 +103,6 @@ class FieldType extends Plugin {
/** /**
* A boolean stating that fields of this type are configurable. * A boolean stating that fields of this type are configurable.
* *
* @todo: Make field module respect this.
*
* @var boolean * @var boolean
*/ */
public $configurable = TRUE; public $configurable = TRUE;
...@@ -112,10 +110,13 @@ class FieldType extends Plugin { ...@@ -112,10 +110,13 @@ class FieldType extends Plugin {
/** /**
* 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.
* *
* If TRUE, fields of this type can only be created programmatically.
*
* @var boolean * @var boolean
*/ */
public $no_ui = FALSE; public $no_ui = FALSE;
/**
* {@inheritdoc}
*/
public $list_class;
} }
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
namespace Drupal\Core\Entity; namespace Drupal\Core\Entity;
use Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
......
...@@ -471,8 +471,16 @@ public function getFieldDefinitions($entity_type, $bundle = NULL) { ...@@ -471,8 +471,16 @@ public function getFieldDefinitions($entity_type, $bundle = NULL) {
} }
else { else {
$class = $this->factory->getPluginClass($entity_type, $this->getDefinition($entity_type)); $class = $this->factory->getPluginClass($entity_type, $this->getDefinition($entity_type));
$base_definitions = $class::baseFieldDefinitions($entity_type);
foreach ($base_definitions as &$base_definition) {
// Support old-style field types to avoid that all base field
// definitions need to be changed.
// @todo: Remove after https://drupal.org/node/2047229.
$base_definition['type'] = preg_replace('/(.+)_field/', 'field_item:$1', $base_definition['type']);
}
$this->entityFieldInfo[$entity_type] = array( $this->entityFieldInfo[$entity_type] = array(
'definitions' => $class::baseFieldDefinitions($entity_type), 'definitions' => $base_definitions,
// Contains definitions of optional (per-bundle) fields. // Contains definitions of optional (per-bundle) fields.
'optional' => array(), 'optional' => array(),
// An array keyed by bundle name containing the optional fields added // An array keyed by bundle name containing the optional fields added
......
...@@ -25,7 +25,6 @@ class FieldTypePluginManager extends DefaultPluginManager { ...@@ -25,7 +25,6 @@ class FieldTypePluginManager extends DefaultPluginManager {
protected $defaults = array( protected $defaults = array(
'settings' => array(), 'settings' => array(),
'instance_settings' => array(), 'instance_settings' => array(),
'list_class' => '\Drupal\field\Plugin\Type\FieldType\ConfigFieldItemList',
); );
/** /**
...@@ -51,6 +50,21 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac ...@@ -51,6 +50,21 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
$this->discovery = new LegacyFieldTypeDiscoveryDecorator($this->discovery, $module_handler); $this->discovery = new LegacyFieldTypeDiscoveryDecorator($this->discovery, $module_handler);
} }
/**
* {@inheritdoc}
*/
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
if (!isset($definition['list_class'])) {
if ($definition['configurable']) {
$definition['list_class'] = '\Drupal\field\Plugin\Type\FieldType\ConfigFieldItemList';
}
else {
$definition['list_class'] = '\Drupal\Core\Entity\Field\FieldItemList';
}
}
}
/** /**
* Returns the default field-level settings for a field type. * Returns the default field-level settings for a field type.
* *
...@@ -81,4 +95,17 @@ public function getDefaultInstanceSettings($type) { ...@@ -81,4 +95,17 @@ public function getDefaultInstanceSettings($type) {
return isset($info['instance_settings']) ? $info['instance_settings'] : array(); return isset($info['instance_settings']) ? $info['instance_settings'] : array();
} }
/**
* Gets the definition of all field types that are configurable.
*
* @return array
* An array of field type definitions.
*/
public function getConfigurableDefinitions() {
$definitions = $this->getDefinitions();
return array_filter($definitions, function ($definition) {
return $definition['configurable'];
});
}
} }
...@@ -2,23 +2,21 @@ ...@@ -2,23 +2,21 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\BooleanItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\BooleanItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Entity\Field\FieldItemBase;
/** /**
* Defines the 'boolean_field' entity field item. * Defines the 'boolean' entity field type.
* *
* @DataType( * @FieldType(
* id = "boolean_field", * id = "boolean",
* label = @Translation("Boolean field item"), * label = @Translation("Boolean"),
* description = @Translation("An entity field containing a boolean value."), * description = @Translation("An entity field containing a boolean value."),
* list_class = "\Drupal\Core\Entity\Field\FieldItemList" * configurable = FALSE
* ) * )
*/ */
class BooleanItem extends FieldItemBase { class BooleanItem extends FieldItemBase {
......
...@@ -2,23 +2,21 @@ ...@@ -2,23 +2,21 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\DateItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\DateItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Entity\Field\FieldItemBase;
/** /**
* Defines the 'date_field' entity field item. * Defines the 'date' entity field type.
* *
* @DataType( * @FieldType(
* id = "date_field", * id = "date",
* label = @Translation("Date field item"), * label = @Translation("Date"),
* description = @Translation("An entity field containing a date value."), * description = @Translation("An entity field containing a date value."),
* list_class = "\Drupal\Core\Entity\Field\FieldItemList" * configurable = FALSE
* ) * )
*/ */
class DateItem extends FieldItemBase { class DateItem extends FieldItemBase {
......
...@@ -2,27 +2,24 @@ ...@@ -2,27 +2,24 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\EmailItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\EmailItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Entity\Field\FieldItemBase;
use Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem;
/** /**
* Defines the 'email_field' entity field item. * Defines the 'email' entity field type.
* *
* @DataType( * @FieldType(
* id = "email_field", * id = "email",
* label = @Translation("E-mail field item"), * label = @Translation("E-mail"),
* description = @Translation("An entity field containing an e-mail value."), * description = @Translation("An entity field containing an e-mail value."),
* list_class = "\Drupal\Core\Entity\Field\FieldItemList" * configurable = FALSE
* ) * )
*/ */
class EmailItem extends LegacyConfigFieldItem { class EmailItem extends FieldItemBase {
/** /**
* Definitions of the contained properties. * Definitions of the contained properties.
...@@ -54,4 +51,5 @@ public function getPropertyDefinitions() { ...@@ -54,4 +51,5 @@ public function getPropertyDefinitions() {
public function isEmpty() { public function isEmpty() {
return $this->value === NULL || $this->value === ''; return $this->value === NULL || $this->value === '';
} }
} }
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\EntityReferenceItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType; use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation; use Drupal\Core\Annotation\Translation;
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\TypedDataInterface;
/** /**
* Defines the 'entity_reference_item' entity field item. * Defines the 'entity_reference' entity field type.
* *
* Supported settings (below the definition's 'settings' key) are: * Supported settings (below the definition's 'settings' key) are:
* - target_type: The entity type to reference. Required. * - target_type: The entity type to reference. Required.
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
* may be referenced. May be set to an single bundle, or to an array of * may be referenced. May be set to an single bundle, or to an array of
* allowed bundles. * allowed bundles.
* *
* @DataType( * @FieldType(
* id = "entity_reference_field", * id = "entity_reference",
* label = @Translation("Entity reference field item"), * label = @Translation("Entity reference"),
* description = @Translation("An entity field containing an entity reference."), * description = @Translation("An entity field containing an entity reference."),
* list_class = "\Drupal\Core\Entity\Field\FieldItemList", * configurable = FALSE,
* constraints = {"ValidReference" = TRUE} * constraints = {"ValidReference" = TRUE}
* ) * )
*/ */
......
...@@ -2,23 +2,21 @@ ...@@ -2,23 +2,21 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\FloatItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\FloatItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Entity\Field\FieldItemBase;
/** /**
* Defines the 'float_field' entity field item. * Defines the 'float' entity field type.
* *
* @DataType( * @FieldType(
* id = "float_field", * id = "float",
* label = @Translation("Float field item"), * label = @Translation("Float"),
* description = @Translation("An entity field containing an float value."), * description = @Translation("An entity field containing an float value."),
* list_class = "\Drupal\Core\Entity\Field\Field" * configurable = FALSE
* ) * )
*/ */
class FloatItem extends FieldItemBase { class FloatItem extends FieldItemBase {
......
...@@ -2,23 +2,21 @@ ...@@ -2,23 +2,21 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\IntegerItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\IntegerItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Entity\Field\FieldItemBase;
/** /**
* Defines the 'integer_field' entity field item. * Defines the 'integer' entity field type.
* *
* @DataType( * @FieldType(
* id = "integer_field", * id = "integer",
* label = @Translation("Integer field item"), * label = @Translation("Integer"),
* description = @Translation("An entity field containing an integer value."), * description = @Translation("An entity field containing an integer value."),
* list_class = "\Drupal\Core\Entity\Field\FieldItemList" * configurable = FALSE
* ) * )
*/ */
class IntegerItem extends FieldItemBase { class IntegerItem extends FieldItemBase {
......
...@@ -2,24 +2,22 @@ ...@@ -2,24 +2,22 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\LanguageItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\LanguageItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Entity\Field\FieldItemBase;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
/** /**
* Defines the 'language_field' entity field item. * Defines the 'language' entity field item.
* *
* @DataType( * @FieldType(
* id = "language_field", * id = "language",
* label = @Translation("Language field item"), * label = @Translation("Language"),
* description = @Translation("An entity field referencing a language."), * description = @Translation("An entity field referencing a language."),
* list_class = "\Drupal\Core\Entity\Field\FieldItemList", * configurable = FALSE,
* constraints = { * constraints = {
* "ComplexData" = { * "ComplexData" = {
* "value" = {"Length" = {"max" = 12}} * "value" = {"Length" = {"max" = 12}}
......
...@@ -2,23 +2,21 @@ ...@@ -2,23 +2,21 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\StringItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\StringItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Entity\Field\FieldItemBase;
/** /**
* Defines the 'string_field' entity field item. * Defines the 'string' entity field type.
* *
* @DataType( * @FieldType(
* id = "string_field", * id = "string",
* label = @Translation("String field item"), * label = @Translation("String"),
* description = @Translation("An entity field containing a string value."), * description = @Translation("An entity field containing a string value."),
* list_class = "\Drupal\Core\Entity\Field\FieldItemList" * configurable = FALSE
* ) * )
*/ */
class StringItem extends FieldItemBase { class StringItem extends FieldItemBase {
......
...@@ -2,23 +2,21 @@ ...@@ -2,23 +2,21 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\UriItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\UriItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Entity\Field\FieldItemBase;
/** /**
* Defines the 'uri_field' entity field item. * Defines the 'uri' entity field type.
* *
* @DataType( * @FieldType(
* id = "uri_field", * id = "uri",
* label = @Translation("URI field item"), * label = @Translation("URI"),
* description = @Translation("An entity field containing a URI."), * description = @Translation("An entity field containing a URI."),
* list_class = "\Drupal\Core\Entity\Field\FieldItemList" * configurable = FALSE
* ) * )
*/ */
class UriItem extends FieldItemBase { class UriItem extends FieldItemBase {
......
...@@ -2,24 +2,21 @@ ...@@ -2,24 +2,21 @@
/** /**
* @file * @file
* Contains \Drupal\Core\Entity\Plugin\DataType\UuidItem. * Contains \Drupal\Core\Entity\Plugin\field\field_type\UuidItem.
*/ */
namespace Drupal\Core\Entity\Plugin\DataType; namespace Drupal\Core\Entity\Plugin\field\field_type;
use Drupal\Core\TypedData\Annotation\DataType;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines the 'uuid_field' entity field item. * Defines the 'uuid' entity field type.
* *
* The field uses a newly generated UUID as default value. * The field uses a newly generated UUID as default value.
* *
* @DataType( * @FieldType(
* id = "uuid_field", * id = "uuid",
* label = @Translation("UUID field item"), * label = @Translation("UUID"),
* description = @Translation("An entity field containing a UUID."), * description = @Translation("An entity field containing a UUID."),
* list_class = "\Drupal\Core\Entity\Field\FieldItemList", * configurable = FALSE,
* constraints = { * constraints = {
* "ComplexData" = { * "ComplexData" = {
* "value" = {"Length" = {"max" = 128}} * "value" = {"Length" = {"max" = 128}}
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\comment; namespace Drupal\comment;
use Drupal\Core\Entity\Plugin\DataType\StringItem; use Drupal\Core\Entity\Plugin\field\field_type\StringItem;
/** /**
* The field item for the 'fieldname' field. * The field item for the 'fieldname' field.
......
...@@ -49,11 +49,8 @@ public function getPropertyDefinitions() { ...@@ -49,11 +49,8 @@ public function getPropertyDefinitions() {
'label' => t('Comment status value'), 'label' => t('Comment status value'),