diff --git a/core/core.services.yml b/core/core.services.yml index b5a8c1853ebb..0659827976a1 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -198,6 +198,7 @@ services: arguments: [slave] typed_data: class: Drupal\Core\TypedData\TypedDataManager + arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] calls: - [setValidationConstraintManager, ['@validation.constraint']] validation.constraint: diff --git a/core/includes/entity.api.php b/core/includes/entity.api.php index 88a801586f57..2219d40bcf19 100644 --- a/core/includes/entity.api.php +++ b/core/includes/entity.api.php @@ -583,13 +583,13 @@ function hook_entity_operation_alter(array &$operations, \Drupal\Core\Entity\Ent /** * Control access to fields. * - * This hook is invoked from \Drupal\Core\Entity\Field\Type\Field::access() to + * This hook is invoked from \Drupal\Core\Entity\Field\Field::access() to * let modules grant or deny operations on fields. * * @param string $operation * The operation to be performed. See * \Drupal\Core\TypedData\AccessibleInterface::access() for possible values. - * @param \Drupal\Core\Entity\Field\Type\Field $field + * @param \Drupal\Core\Entity\Field\Field $field * The entity field object on which the operation is to be performed. * @param \Drupal\Core\Session\AccountInterface $account * The user account to check. @@ -617,7 +617,7 @@ function hook_entity_field_access($operation, $field, \Drupal\Core\Session\Accou * @param array $context * Context array on the performed operation with the following keys: * - operation: The operation to be performed (string). - * - field: The entity field object (\Drupal\Core\Entity\Field\Type\Field). + * - field: The entity field object (\Drupal\Core\Entity\Field\Field). * - account: The user account to check access for * (Drupal\user\Plugin\Core\Entity\User). */ diff --git a/core/lib/Drupal/Core/Config/Schema/SchemaDiscovery.php b/core/lib/Drupal/Core/Config/Schema/SchemaDiscovery.php deleted file mode 100644 index 51e684af42e2..000000000000 --- a/core/lib/Drupal/Core/Config/Schema/SchemaDiscovery.php +++ /dev/null @@ -1,122 +0,0 @@ -storage = $storage; - $this->loadAllSchema(); - } - - /** - * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition(). - */ - public function getDefinition($base_plugin_id) { - if (isset($this->definitions[$base_plugin_id])) { - $type = $base_plugin_id; - } - elseif (strpos($base_plugin_id, '.') && $name = $this->getFallbackName($base_plugin_id)) { - // Found a generic name, replacing the last element by '*'. - $type = $name; - } - else { - // If we don't have definition, return the 'default' element. - // This should map to 'undefined' type by default, unless overridden. - $type = 'default'; - } - $definition = $this->definitions[$type]; - // Check whether this type is an extension of another one and compile it. - if (isset($definition['type'])) { - $merge = $this->getDefinition($definition['type']); - $definition = NestedArray::mergeDeep($merge, $definition); - // Unset type so we try the merge only once per type. - unset($definition['type']); - $this->definitions[$type] = $definition; - } - return $definition; - } - - /** - * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). - */ - public function getDefinitions() { - return $this->definitions; - } - - /** - * Load schema for module / theme. - */ - protected function loadAllSchema() { - foreach ($this->storage->listAll() as $name) { - if ($schema = $this->storage->read($name)) { - foreach ($schema as $type => $definition) { - $this->definitions[$type] = $definition; - } - } - } - } - - /** - * Gets fallback metadata name. - * - * @param string $name - * Configuration name or key. - * - * @return null|string - * Same name with the last part(s) replaced by the filesystem marker. - * for example, breakpoint.breakpoint.module.toolbar.narrow check for - * definition in below order: - * breakpoint.breakpoint.module.toolbar.* - * breakpoint.breakpoint.module.*.* - * breakpoint.breakpoint.*.*.* - * breakpoint.*.*.*.* - * Returns null, if no matching element. - */ - protected function getFallbackName($name) { - // Check for definition of $name with filesystem marker. - $replaced = preg_replace('/(\.[^\.]+)([\.\*]*)$/', '.*\2', $name); - if ($replaced != $name ) { - if (isset($this->definitions[$replaced])) { - return $replaced; - } - else { - // No definition for this level(for example, breakpoint.breakpoint.*), - // check for next level (which is, breakpoint.*.*). - return self::getFallbackName($replaced); - } - } - } -} diff --git a/core/lib/Drupal/Core/Config/TypedConfigElementFactory.php b/core/lib/Drupal/Core/Config/TypedConfigElementFactory.php deleted file mode 100644 index 7ff512985790..000000000000 --- a/core/lib/Drupal/Core/Config/TypedConfigElementFactory.php +++ /dev/null @@ -1,28 +0,0 @@ -discovery->getDefinition($plugin_id); - $configuration += $type_definition; - return parent::createInstance($plugin_id, $configuration, $name, $parent); - } -} diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index 4a8a289b5c3b..00c14be47639 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -7,13 +7,13 @@ namespace Drupal\Core\Config; -use Drupal\Core\Config\Schema\SchemaDiscovery; -use Drupal\Core\TypedData\TypedDataManager; +use Drupal\Component\Plugin\PluginManagerBase; +use Drupal\Component\Utility\NestedArray; /** * Manages config type plugins. */ -class TypedConfigManager extends TypedDataManager { +class TypedConfigManager extends PluginManagerBase { /** * A storage controller instance for reading configuration data. @@ -22,6 +22,20 @@ class TypedConfigManager extends TypedDataManager { */ protected $configStorage; + /** + * A storage controller instance for reading configuration schema data. + * + * @var \Drupal\Core\Config\StorageInterface + */ + protected $schemaStorage; + + /** + * The array of plugin definitions, keyed by plugin id. + * + * @var array + */ + protected $definitions = array(); + /** * Creates a new typed configuration manager. * @@ -32,8 +46,8 @@ class TypedConfigManager extends TypedDataManager { */ public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage) { $this->configStorage = $configStorage; - $this->discovery = new SchemaDiscovery($schemaStorage); - $this->factory = new TypedConfigElementFactory($this->discovery); + $this->schemaStorage = $schemaStorage; + $this->loadAllSchema(); } /** @@ -78,7 +92,116 @@ class TypedConfigManager extends TypedDataManager { $definition['type'] = $this->replaceName($definition['type'], $replace); } // Create typed config object. - return parent::create($definition, $value, $name, $parent); + $wrapper = $this->createInstance($definition['type'], $definition, $name, $parent); + if (isset($value)) { + $wrapper->setValue($value, FALSE); + } + return $wrapper; + } + + /** + * Overrides Drupal\Core\TypedData\TypedDataFactory::createInstance(). + */ + public function createInstance($plugin_id, array $configuration, $name = NULL, $parent = NULL) { + $type_definition = $this->getDefinition($plugin_id); + $configuration += $type_definition; + if (!isset($type_definition)) { + throw new InvalidArgumentException(format_string('Invalid data type %plugin_id has been given.', array('%plugin_id' => $plugin_id))); + } + + // Allow per-data definition overrides of the used classes, i.e. take over + // classes specified in the data definition. + $key = empty($configuration['list']) ? 'class' : 'list class'; + if (isset($configuration[$key])) { + $class = $configuration[$key]; + } + elseif (isset($type_definition[$key])) { + $class = $type_definition[$key]; + } + + if (!isset($class)) { + throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id)); + } + return new $class($configuration, $name, $parent); + } + + /** + * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition(). + */ + public function getDefinition($base_plugin_id) { + if (isset($this->definitions[$base_plugin_id])) { + $type = $base_plugin_id; + } + elseif (strpos($base_plugin_id, '.') && $name = $this->getFallbackName($base_plugin_id)) { + // Found a generic name, replacing the last element by '*'. + $type = $name; + } + else { + // If we don't have definition, return the 'default' element. + // This should map to 'undefined' type by default, unless overridden. + $type = 'default'; + } + $definition = $this->definitions[$type]; + // Check whether this type is an extension of another one and compile it. + if (isset($definition['type'])) { + $merge = $this->getDefinition($definition['type']); + $definition = NestedArray::mergeDeep($merge, $definition); + // Unset type so we try the merge only once per type. + unset($definition['type']); + $this->definitions[$type] = $definition; + } + return $definition; + } + + /** + * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). + */ + public function getDefinitions() { + return $this->definitions; + } + + /** + * Load schema for module / theme. + */ + protected function loadAllSchema() { + foreach ($this->schemaStorage->listAll() as $name) { + if ($schema = $this->schemaStorage->read($name)) { + foreach ($schema as $type => $definition) { + $this->definitions[$type] = $definition; + } + } + } + } + + /** + * Gets fallback metadata name. + * + * @param string $name + * Configuration name or key. + * + * @return null|string + * Same name with the last part(s) replaced by the filesystem marker. + * for example, breakpoint.breakpoint.module.toolbar.narrow check for + * definition in below order: + * breakpoint.breakpoint.module.toolbar.* + * breakpoint.breakpoint.module.*.* + * breakpoint.breakpoint.*.*.* + * breakpoint.*.*.*.* + * Returns null, if no matching element. + */ + protected function getFallbackName($name) { + // Check for definition of $name with filesystem marker. + $replaced = preg_replace('/(\.[^\.]+)([\.\*]*)$/', '.*\2', $name); + if ($replaced != $name ) { + if (isset($this->definitions[$replaced])) { + return $replaced; + } + else { + // No definition for this level(for example, breakpoint.breakpoint.*), + // check for next level (which is, breakpoint.*.*). + return self::getFallbackName($replaced); + } + } } /** diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 8b73f126affe..c3687a06604b 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -369,7 +369,7 @@ class EntityNG extends Entity { /** * Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslation(). * - * @return \Drupal\Core\Entity\Field\Type\EntityTranslation + * @return \Drupal\Core\Entity\Plugin\DataType\EntityTranslation */ public function getTranslation($langcode, $strict = TRUE) { // If the default language is Language::LANGCODE_NOT_SPECIFIED, the entity is not diff --git a/core/lib/Drupal/Core/Entity/Field/Type/Field.php b/core/lib/Drupal/Core/Entity/Field/Field.php similarity index 98% rename from core/lib/Drupal/Core/Entity/Field/Type/Field.php rename to core/lib/Drupal/Core/Entity/Field/Field.php index 4d53c18c75ee..3948ddf80f28 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/Field.php +++ b/core/lib/Drupal/Core/Entity/Field/Field.php @@ -2,10 +2,10 @@ /** * @file - * Contains \Drupal\Core\Entity\Field\Type\Field. + * Contains \Drupal\Core\Entity\Field\Field. */ -namespace Drupal\Core\Entity\Field\Type; +namespace Drupal\Core\Entity\Field; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\Core\Session\AccountInterface; diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index 46a66b9976fe..cb243d532874 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Entity\Field; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\TypedData\Type\Map; +use Drupal\Core\TypedData\Plugin\DataType\Map; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\user; @@ -80,7 +80,7 @@ abstract class FieldItemBase extends Map implements FieldItemInterface { } /** - * Overrides \Drupal\Core\TypedData\Type\Map::set(). + * {@inheritdoc} */ public function set($property_name, $value, $notify = TRUE) { // Notify the parent of any changes to be made. diff --git a/core/lib/Drupal/Core/Entity/Field/Type/UuidItem.php b/core/lib/Drupal/Core/Entity/Field/Type/UuidItem.php deleted file mode 100644 index 855d942a81f3..000000000000 --- a/core/lib/Drupal/Core/Entity/Field/Type/UuidItem.php +++ /dev/null @@ -1,28 +0,0 @@ -setValue(array('value' => $uuid->generate()), $notify); - return $this; - } -} diff --git a/core/lib/Drupal/Core/Entity/Field/Type/BooleanItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/BooleanItem.php similarity index 62% rename from core/lib/Drupal/Core/Entity/Field/Type/BooleanItem.php rename to core/lib/Drupal/Core/Entity/Plugin/DataType/BooleanItem.php index f73b013b2a6a..367cc746ded3 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/BooleanItem.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/BooleanItem.php @@ -2,15 +2,24 @@ /** * @file - * Contains \Drupal\Core\Entity\Field\Type\BooleanItem. + * Contains \Drupal\Core\Entity\Plugin\DataType\BooleanItem. */ -namespace Drupal\Core\Entity\Field\Type; +namespace Drupal\Core\Entity\Plugin\DataType; +use Drupal\Core\TypedData\Annotation\DataType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\Field\FieldItemBase; /** * Defines the 'boolean_field' entity field item. + * + * @DataType( + * id = "boolean_field", + * label = @Translation("Boolean field item"), + * description = @Translation("An entity field containing a boolean value."), + * list_class = "\Drupal\Core\Entity\Field\Field" + * ) */ class BooleanItem extends FieldItemBase { diff --git a/core/lib/Drupal/Core/Entity/Field/Type/DateItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/DateItem.php similarity index 62% rename from core/lib/Drupal/Core/Entity/Field/Type/DateItem.php rename to core/lib/Drupal/Core/Entity/Plugin/DataType/DateItem.php index 33b4ec42a72c..3fd9aa66cf17 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/DateItem.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/DateItem.php @@ -2,15 +2,24 @@ /** * @file - * Contains \Drupal\Core\Entity\Field\Type\DateItem. + * Contains \Drupal\Core\Entity\Plugin\DataType\DateItem. */ -namespace Drupal\Core\Entity\Field\Type; +namespace Drupal\Core\Entity\Plugin\DataType; +use Drupal\Core\TypedData\Annotation\DataType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\Field\FieldItemBase; /** * Defines the 'date_field' entity field item. + * + * @DataType( + * id = "date_field", + * label = @Translation("Date field item"), + * description = @Translation("An entity field containing a date value."), + * list_class = "\Drupal\Core\Entity\Field\Field" + * ) */ class DateItem extends FieldItemBase { diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EmailItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EmailItem.php similarity index 64% rename from core/lib/Drupal/Core/Entity/Field/Type/EmailItem.php rename to core/lib/Drupal/Core/Entity/Plugin/DataType/EmailItem.php index 6d878ed2c1b3..b147976c9c07 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EmailItem.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EmailItem.php @@ -2,15 +2,25 @@ /** * @file - * Contains \Drupal\Core\Entity\Field\Type\EmailItem. + * Contains \Drupal\Core\Entity\Plugin\DataType\EmailItem. */ -namespace Drupal\Core\Entity\Field\Type; +namespace Drupal\Core\Entity\Plugin\DataType; +use Drupal\Core\TypedData\Annotation\DataType; +use Drupal\Core\Annotation\Translation; +use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem; /** * Defines the 'email_field' entity field item. + * + * @DataType( + * id = "email_field", + * label = @Translation("E-mail field item"), + * description = @Translation("An entity field containing an e-mail value."), + * list_class = "\Drupal\Core\Entity\Field\Field" + * ) */ class EmailItem extends LegacyConfigFieldItem { @@ -37,6 +47,7 @@ class EmailItem extends LegacyConfigFieldItem { return static::$propertyDefinitions; } + /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReferenceItem.php similarity index 87% rename from core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php rename to core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReferenceItem.php index f568aec5ec8a..7f756ada3507 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReferenceItem.php @@ -2,11 +2,13 @@ /** * @file - * Contains \Drupal\Core\Entity\Field\Type\EntityReferenceItem. + * Contains \Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem. */ -namespace Drupal\Core\Entity\Field\Type; +namespace Drupal\Core\Entity\Plugin\DataType; +use Drupal\Core\TypedData\Annotation\DataType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\TypedData\TypedDataInterface; @@ -15,6 +17,13 @@ use Drupal\Core\TypedData\TypedDataInterface; * * Required settings (below the definition's 'settings' key) are: * - target_type: The entity type to reference. + * + * @DataType( + * id = "entity_reference_field", + * label = @Translation("Entity reference field item"), + * description = @Translation("An entity field containing an entity reference."), + * list_class = "\Drupal\Core\Entity\Field\Field" + * ) */ class EntityReferenceItem extends FieldItemBase { diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTranslation.php similarity index 94% rename from core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php rename to core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTranslation.php index 859fa9ad9bce..8a3912641bb9 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTranslation.php @@ -2,17 +2,18 @@ /** * @file - * Contains \Drupal\Core\Entity\Type\EntityTranslation. + * Contains \Drupal\Core\Entity\Plugin\DataType\EntityTranslation. */ -namespace Drupal\Core\Entity\Field\Type; +namespace Drupal\Core\Entity\Plugin\DataType; +use Drupal\Core\TypedData\Annotation\DataType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\AccessibleInterface; use Drupal\Core\TypedData\ComplexDataInterface; use Drupal\Core\TypedData\TypedData; use ArrayIterator; -use Drupal\Core\TypedData\TypedDataInterface; use IteratorAggregate; use InvalidArgumentException; @@ -21,6 +22,12 @@ use InvalidArgumentException; * * Via this object translated entity fields may be read and updated in the same * way as untranslatable entity fields on the entity object. + * + * @DataType( + * id = "entity_translation", + * label = @Translation("Entity translation"), + * description = @Translation("A translation of an entity.") + * ) */ class EntityTranslation extends TypedData implements IteratorAggregate, AccessibleInterface, ComplexDataInterface { diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityWrapper.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityWrapper.php similarity index 94% rename from core/lib/Drupal/Core/Entity/Field/Type/EntityWrapper.php rename to core/lib/Drupal/Core/Entity/Plugin/DataType/EntityWrapper.php index 2b2b54a85141..e2561a90c85c 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityWrapper.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityWrapper.php @@ -2,11 +2,13 @@ /** * @file - * Contains \Drupal\Core\Entity\Field\Type\EntityWrapper. + * Contains \Drupal\Core\Entity\Plugin\DataType\EntityWrapper. */ -namespace Drupal\Core\Entity\Field\Type; +namespace Drupal\Core\Entity\Plugin\DataType; +use Drupal\Core\TypedData\Annotation\DataType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\TypedData\ComplexDataInterface; use Drupal\Core\TypedData\TypedData; @@ -34,6 +36,12 @@ use InvalidArgumentException; * Supported settings (below the definition's 'settings' key) are: * - id source: If used as computed property, the ID property used to load * the entity object. + * + * @DataType( + * id = "entity", + * label = @Translation("Entity"), + * description = @Translation("All kind of entities, e.g. nodes, comments or users.") + * ) */ class EntityWrapper extends TypedData implements IteratorAggregate, ComplexDataInterface { diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldDataTypeDerivative.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldDataTypeDerivative.php index 504e427ae724..346b656a4f9d 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldDataTypeDerivative.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldDataTypeDerivative.php @@ -38,11 +38,6 @@ class FieldDataTypeDerivative implements DerivativeInterface { */ public function getDerivativeDefinitions(array $base_plugin_definition) { foreach (\Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions() as $plugin_id => $definition) { - // Typed data API expects a 'list class' property, but annotations do not - // support spaces in property names. - $definition['list class'] = $definition['list_class']; - unset($definition['list_class']); - $this->derivatives[$plugin_id] = $definition; } return $this->derivatives; diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldItem.php new file mode 100644 index 000000000000..73309d94a9ad --- /dev/null +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldItem.php @@ -0,0 +1,26 @@ +setValue(array('value' => $uuid->generate()), $notify); + return $this; + } +} diff --git a/core/lib/Drupal/Core/Plugin/Context/Context.php b/core/lib/Drupal/Core/Plugin/Context/Context.php index cc9f355d099c..3ed63585e8db 100644 --- a/core/lib/Drupal/Core/Plugin/Context/Context.php +++ b/core/lib/Drupal/Core/Plugin/Context/Context.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Plugin\Context; use Drupal\Component\Plugin\Context\Context as ComponentContext; -use Drupal\Core\Entity\Field\Type\EntityWrapper; +use Drupal\Core\Entity\Plugin\DataType\EntityWrapper; use Drupal\Core\TypedData\ComplexDataInterface; use Drupal\Core\TypedData\ListInterface; use Drupal\Core\TypedData\TypedDataInterface; diff --git a/core/lib/Drupal/Core/TypedData/Annotation/DataType.php b/core/lib/Drupal/Core/TypedData/Annotation/DataType.php new file mode 100644 index 000000000000..c0569ab1fce1 --- /dev/null +++ b/core/lib/Drupal/Core/TypedData/Annotation/DataType.php @@ -0,0 +1,91 @@ +discovery->getDefinition($plugin_id); - - if (!isset($type_definition)) { - throw new InvalidArgumentException(format_string('Invalid data type %plugin_id has been given.', array('%plugin_id' => $plugin_id))); - } - - // Allow per-data definition overrides of the used classes, i.e. take over - // classes specified in the data definition. - $key = empty($configuration['list']) ? 'class' : 'list class'; - if (isset($configuration[$key])) { - $class = $configuration[$key]; - } - elseif (isset($type_definition[$key])) { - $class = $type_definition[$key]; - } - - if (!isset($class)) { - throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id)); - } - return new $class($configuration, $name, $parent); - } -} diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index c0f81b9dce89..7e72bb595313 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -7,12 +7,11 @@ namespace Drupal\Core\TypedData; +use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Language\LanguageManager; +use Drupal\Core\Plugin\DefaultPluginManager; use InvalidArgumentException; -use Drupal\Component\Plugin\Discovery\ProcessDecorator; -use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; -use Drupal\Component\Plugin\PluginManagerBase; -use Drupal\Core\Plugin\Discovery\CacheDecorator; -use Drupal\Core\Plugin\Discovery\HookDiscovery; use Drupal\Core\TypedData\Validation\MetadataFactory; use Drupal\Core\Validation\ConstraintManager; use Drupal\Core\Validation\DrupalTranslator; @@ -22,7 +21,7 @@ use Symfony\Component\Validator\Validation; /** * Manages data type plugins. */ -class TypedDataManager extends PluginManagerBase { +class TypedDataManager extends DefaultPluginManager { /** * The validator used for validating typed data. @@ -38,17 +37,6 @@ class TypedDataManager extends PluginManagerBase { */ protected $constraintManager; - /** - * Type definition defaults which are merged in by the ProcessDecorator. - * - * @see \Drupal\Component\Plugin\PluginManagerBase::processDefinition() - * - * @var array - */ - protected $defaults = array( - 'list class' => '\Drupal\Core\TypedData\ItemList', - ); - /** * An array of typed data property prototypes. * @@ -56,13 +44,14 @@ class TypedDataManager extends PluginManagerBase { */ protected $prototypes = array(); - public function __construct() { - $this->discovery = new HookDiscovery('data_type_info'); - $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); - $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); - $this->discovery = new CacheDecorator($this->discovery, 'typed_data:types'); + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { + $this->alterInfo($module_handler, 'data_type_info'); + $this->setCacheBackend($cache_backend, $language_manager, 'typed_data:types'); - $this->factory = new TypedDataFactory($this->discovery); + $annotation_namespaces = array( + 'Drupal\Core\TypedData\Annotation' => DRUPAL_ROOT . '/core/lib', + ); + parent::__construct('DataType', $namespaces, $annotation_namespaces, 'Drupal\Core\TypedData\Annotation\DataType'); } /** @@ -84,7 +73,26 @@ class TypedDataManager extends PluginManagerBase { * The instantiated typed data object. */ public function createInstance($plugin_id, array $configuration, $name = NULL, $parent = NULL) { - return $this->factory->createInstance($plugin_id, $configuration, $name, $parent); + $type_definition = $this->getDefinition($plugin_id); + + if (!isset($type_definition)) { + throw new InvalidArgumentException(format_string('Invalid data type %plugin_id has been given.', array('%plugin_id' => $plugin_id))); + } + + // Allow per-data definition overrides of the used classes, i.e. take over + // classes specified in the data definition. + $key = empty($configuration['list']) ? 'class' : 'list_class'; + if (isset($configuration[$key])) { + $class = $configuration[$key]; + } + elseif (isset($type_definition[$key])) { + $class = $type_definition[$key]; + } + + if (!isset($class)) { + throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id)); + } + return new $class($configuration, $name, $parent); } /** @@ -104,13 +112,13 @@ class TypedDataManager extends PluginManagerBase { * - class: If set and 'list' is FALSE, the class to use for creating the * typed data object; otherwise the default class of the data type will be * used. - * - list class: If set and 'list' is TRUE, the class to use for creating + * - list_class: If set and 'list' is TRUE, the class to use for creating * the typed data object; otherwise the default list class of the data * type will be used. * - settings: An array of settings, as required by the used 'class'. See * the documentation of the class for supported or required settings. - * - list settings: An array of settings as required by the used - * 'list class'. See the documentation of the list class for support or + * - list_settings: An array of settings as required by the used + * 'list_class'. See the documentation of the list class for support or * required settings. * - constraints: An array of validation constraints. See * \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details. @@ -134,18 +142,18 @@ class TypedDataManager extends PluginManagerBase { * * @see \Drupal::typedData() * @see \Drupal\Core\TypedData\TypedDataManager::getPropertyInstance() - * @see \Drupal\Core\TypedData\Type\Integer - * @see \Drupal\Core\TypedData\Type\Float - * @see \Drupal\Core\TypedData\Type\String - * @see \Drupal\Core\TypedData\Type\Boolean - * @see \Drupal\Core\TypedData\Type\Duration - * @see \Drupal\Core\TypedData\Type\Date - * @see \Drupal\Core\TypedData\Type\Uri - * @see \Drupal\Core\TypedData\Type\Binary + * @see \Drupal\Core\TypedData\Plugin\DataType\Integer + * @see \Drupal\Core\TypedData\Plugin\DataType\Float + * @see \Drupal\Core\TypedData\Plugin\DataType\String + * @see \Drupal\Core\TypedData\Plugin\DataType\Boolean + * @see \Drupal\Core\TypedData\Plugin\DataType\Duration + * @see \Drupal\Core\TypedData\Plugin\DataType\Date + * @see \Drupal\Core\TypedData\Plugin\DataType\Uri + * @see \Drupal\Core\TypedData\Plugin\DataType\Binary * @see \Drupal\Core\Entity\Field\EntityWrapper */ public function create(array $definition, $value = NULL, $name = NULL, $parent = NULL) { - $wrapper = $this->factory->createInstance($definition['type'], $definition, $name, $parent); + $wrapper = $this->createInstance($definition['type'], $definition, $name, $parent); if (isset($value)) { $wrapper->setValue($value, FALSE); } @@ -349,12 +357,16 @@ class TypedDataManager extends PluginManagerBase { $type_definition = $this->getDefinition($definition['type']); // Auto-generate a constraint for the primitive type if we have a mapping. - if (isset($type_definition['primitive type'])) { - $constraints[] = $validation_manager->create('PrimitiveType', array('type' => $type_definition['primitive type'])); + if (isset($type_definition['primitive_type'])) { + $constraints[] = $validation_manager->create('PrimitiveType', array('type' => $type_definition['primitive_type'])); } // Add in constraints specified by the data type. if (isset($type_definition['constraints'])) { foreach ($type_definition['constraints'] as $name => $options) { + // Annotations do not support empty arrays. + if ($options === TRUE) { + $options = array(); + } $constraints[] = $validation_manager->create($name, $options); } } diff --git a/core/modules/comment/lib/Drupal/comment/FieldNewItem.php b/core/modules/comment/lib/Drupal/comment/FieldNewItem.php index 73fabe55f444..3e23ae791cba 100644 --- a/core/modules/comment/lib/Drupal/comment/FieldNewItem.php +++ b/core/modules/comment/lib/Drupal/comment/FieldNewItem.php @@ -7,7 +7,7 @@ namespace Drupal\comment; -use Drupal\Core\Entity\Field\Type\IntegerItem; +use Drupal\Core\Entity\Plugin\DataType\IntegerItem; /** * The field item for the 'new' field. diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php index 7e493dbef3c7..d3bceb863b8c 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php @@ -66,7 +66,7 @@ class ConfigSchemaTest extends DrupalUnitTestBase { $definition = $config['testitem']->getDefinition(); $expected = array(); $expected['label'] = 'Test item'; - $expected['class'] = '\Drupal\Core\TypedData\Type\String'; + $expected['class'] = '\Drupal\Core\TypedData\Plugin\DataType\String'; $expected['type'] = 'string'; $this->assertEqual($definition, $expected, 'Automatic type detection on string item worked.'); $definition = $config['testlist']->getDefinition(); @@ -162,12 +162,12 @@ class ConfigSchemaTest extends DrupalUnitTestBase { // Try some simple properties. $meta = config_typed()->get('system.site'); $property = $meta->get('name'); - $this->assertTrue(is_a($property, 'Drupal\Core\TypedData\Type\String'), 'Got the right wrapper fo the site name property.'); + $this->assertTrue(is_a($property, 'Drupal\Core\TypedData\Plugin\DataType\String'), 'Got the right wrapper fo the site name property.'); $this->assertEqual($property->getType(), 'label', 'Got the right string type for site name data.'); $this->assertEqual($property->getValue(), 'Drupal', 'Got the right string value for site name data.'); $property = $meta->get('page')->get('front'); - $this->assertTrue(is_a($property, 'Drupal\Core\TypedData\Type\String'), 'Got the right wrapper fo the page.front property.'); + $this->assertTrue(is_a($property, 'Drupal\Core\TypedData\Plugin\DataType\String'), 'Got the right wrapper fo the page.front property.'); $this->assertEqual($property->getType(), 'path', 'Got the right type for page.front data (undefined).'); $this->assertEqual($property->getValue(), 'user', 'Got the right value for page.front data.'); diff --git a/core/modules/email/email.module b/core/modules/email/email.module index 2d24c39f0087..6afbdebfc8b3 100644 --- a/core/modules/email/email.module +++ b/core/modules/email/email.module @@ -28,7 +28,7 @@ function email_field_info() { 'description' => t('This field stores an e-mail address in the database.'), 'default_widget' => 'email_default', 'default_formatter' => 'email_mailto', - 'class' => 'Drupal\Core\Entity\Field\Type\EmailItem', + 'class' => 'Drupal\Core\Entity\Plugin\DataType\EmailItem', ), ); } diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index b5d70a5fa651..df36e0d73d69 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -40,7 +40,7 @@ function entity_reference_field_info() { * * Set the "target_type" property definition for entity reference fields. * - * @see \Drupal\Core\Entity\Field\Type\EntityReferenceItem::getPropertyDefinitions() + * @see \Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem::getPropertyDefinitions() * * @param array $info * The property info array as returned by hook_entity_field_info(). diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Type/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Type/ConfigurableEntityReferenceItem.php index f02490d9a18b..287ab8140f30 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Type/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Type/ConfigurableEntityReferenceItem.php @@ -7,7 +7,7 @@ namespace Drupal\entity_reference\Type; -use Drupal\Core\Entity\Field\Type\EntityReferenceItem; +use Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem; use Drupal\field\Plugin\Type\FieldType\ConfigEntityReferenceItemBase; use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface; diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php index 7406134aace9..7229a9ab3a5e 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php @@ -7,7 +7,7 @@ namespace Drupal\field\Plugin\Type\FieldType; -use Drupal\Core\Entity\Field\Type\EntityReferenceItem; +use Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem; use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface; use Drupal\field\Plugin\Core\Entity\Field; diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php index 31341609ae7e..dfc4fba791b9 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php @@ -8,7 +8,7 @@ namespace Drupal\field\Plugin\Type\FieldType; use Drupal\Core\TypedData\TypedDataInterface; -use Drupal\Core\Entity\Field\Type\Field; +use Drupal\Core\Entity\Field\Field; use Drupal\field\Field as FieldAPI; /** diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php index f3e67b5d0449..71436543cf7f 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php @@ -19,7 +19,7 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR * * @var string */ - protected $supportedInterfaceOrClass = 'Drupal\Core\Entity\Field\Type\EntityReferenceItem'; + protected $supportedInterfaceOrClass = 'Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem'; /** * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() diff --git a/core/modules/path/lib/Drupal/path/Type/PathItem.php b/core/modules/path/lib/Drupal/path/Plugin/DataType/PathItem.php similarity index 66% rename from core/modules/path/lib/Drupal/path/Type/PathItem.php rename to core/modules/path/lib/Drupal/path/Plugin/DataType/PathItem.php index 9b8abd1cf385..e72e3a7ac9d1 100644 --- a/core/modules/path/lib/Drupal/path/Type/PathItem.php +++ b/core/modules/path/lib/Drupal/path/Plugin/DataType/PathItem.php @@ -2,15 +2,24 @@ /** * @file - * Contains \Drupal\path\Type\PathItem. + * Contains \Drupal\path\Plugin\DataType\PathItem. */ -namespace Drupal\path\Type; +namespace Drupal\path\Plugin\DataType; +use Drupal\Core\TypedData\Annotation\DataType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\Field\FieldItemBase; /** * Defines the 'path_field' entity field item. + * + * @DataType( + * id = "path_field", + * label = @Translation("Path field item"), + * description = @Translation("An entity field containing a path alias and related data."), + * list_class = "\Drupal\Core\Entity\Field\Field" + * ) */ class PathItem extends FieldItemBase { diff --git a/core/modules/path/path.module b/core/modules/path/path.module index efc59a8b3927..4cb0ddd87c0c 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -262,19 +262,6 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) { } } -/** - * Implements hook_data_type_info(). - */ -function path_data_type_info() { - $info['path_field'] = array( - 'label' => t('Path field item'), - 'description' => t('An entity field containing a path alias and related data.'), - 'class' => '\Drupal\path\Type\PathItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - ); - return $info; -} - /** * Implements hook_entity_field_info(). */ diff --git a/core/modules/system/config/schema/system.data_types.schema.yml b/core/modules/system/config/schema/system.data_types.schema.yml index ad4e4eccbc20..15e4c6368e2e 100644 --- a/core/modules/system/config/schema/system.data_types.schema.yml +++ b/core/modules/system/config/schema/system.data_types.schema.yml @@ -1,22 +1,22 @@ # Basic scalar data types from typed data. boolean: label: 'Boolean' - class: '\Drupal\Core\TypedData\Type\Boolean' + class: '\Drupal\Core\TypedData\Plugin\DataType\Boolean' email: label: 'Email' - class: '\Drupal\Core\TypedData\Type\Email' + class: '\Drupal\Core\TypedData\Plugin\DataType\Email' integer: label: 'Integer' - class: '\Drupal\Core\TypedData\Type\Integer' + class: '\Drupal\Core\TypedData\Plugin\DataType\Integer' float: label: 'Float' - class: '\Drupal\Core\TypedData\Type\Float' + class: '\Drupal\Core\TypedData\Plugin\DataType\Float' string: label: 'String' - class: '\Drupal\Core\TypedData\Type\String' + class: '\Drupal\Core\TypedData\Plugin\DataType\String' uri: label: 'Uri' - class: '\Drupal\Core\TypedData\Type\Uri' + class: '\Drupal\Core\TypedData\Plugin\DataType\Uri' # Basic data types for configuration. undefined: diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index c72febdb813b..d550f363ebe8 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -131,57 +131,6 @@ function hook_cron() { } } -/** - * Defines available data types for the typed data API. - * - * The typed data API allows modules to support any kind of data based upon - * pre-defined primitive types and interfaces for complex data and lists. - * - * Defined data types may map to one of the pre-defined primitive types in - * \Drupal\Core\TypedData\Primitive or may be complex data types, containing one - * or more data properties. Typed data objects for complex data types have to - * implement the \Drupal\Core\TypedData\ComplexDataInterface. Further interfaces - * that may be implemented are: - * - \Drupal\Core\TypedData\AccessibleInterface - * - \Drupal\Core\TypedData\TranslatableInterface - * - * Furthermore, lists of data items are represented by objects implementing - * the \Drupal\Core\TypedData\ListInterface. A list contains items of the same - * data type, is ordered and may contain duplicates. The classed used for a list - * of items of a certain type may be specified using the 'list class' key. - * - * @return array - * An associative array where the key is the data type name and the value is - * again an associative array. Supported keys are: - * - label: The human readable label of the data type. - * - class: The associated typed data class. Must implement the - * \Drupal\Core\TypedData\TypedDataInterface. - * - list class: (optional) A typed data class used for wrapping multiple - * data items of the type. Must implement the - * \Drupal\Core\TypedData\ListInterface. Defaults to - * \Drupal\Core\TypedData\ItemList; - * - primitive type: (optional) Maps the data type to one of the pre-defined - * primitive types in \Drupal\Core\TypedData\Primitive. If set, it must be - * a constant defined by \Drupal\Core\TypedData\Primitive such as - * \Drupal\Core\TypedData\Primitive::STRING. - * - constraints: An array of validation constraints for this type. See - * \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details. - * - * @see \Drupal::typedData() - * @see Drupal\Core\TypedData\TypedDataManager::create() - * @see hook_data_type_info_alter() - */ -function hook_data_type_info() { - return array( - 'email' => array( - 'label' => t('Email'), - 'class' => '\Drupal\email\Type\Email', - 'primitive type' => \Drupal\Core\TypedData\Primitive::STRING, - 'constraints' => array('Email' => array()), - ), - ); -} - /** * Alter available data types for typed data wrappers. * diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 238f303fee8a..87fe50de2cf8 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2161,152 +2161,6 @@ function system_stream_wrappers() { return $wrappers; } -/** - * Implements hook_data_type_info(). - */ -function system_data_type_info() { - return array( - 'boolean' => array( - 'label' => t('Boolean'), - 'class' => '\Drupal\Core\TypedData\Type\Boolean', - 'primitive type' => Primitive::BOOLEAN, - ), - 'string' => array( - 'label' => t('String'), - 'class' => '\Drupal\Core\TypedData\Type\String', - 'primitive type' => Primitive::STRING, - ), - 'integer' => array( - 'label' => t('Integer'), - 'class' => '\Drupal\Core\TypedData\Type\Integer', - 'primitive type' => Primitive::INTEGER, - ), - 'float' => array( - 'label' => t('Float'), - 'class' => '\Drupal\Core\TypedData\Type\Float', - 'primitive type' => Primitive::FLOAT, - ), - 'date' => array( - 'label' => t('Date'), - 'class' => '\Drupal\Core\TypedData\Type\Date', - 'primitive type' => Primitive::DATE, - ), - 'duration' => array( - 'label' => t('Duration'), - 'class' => '\Drupal\Core\TypedData\Type\Duration', - 'primitive type' => Primitive::DURATION, - ), - 'uri' => array( - 'label' => t('URI'), - 'class' => '\Drupal\Core\TypedData\Type\Uri', - 'primitive type' => Primitive::URI, - ), - 'email' => array( - 'label' => t('Email'), - 'class' => '\Drupal\Core\TypedData\Type\Email', - 'primitive type' => Primitive::STRING, - 'constraints' => array('Email' => array()), - ), - 'binary' => array( - 'label' => t('Binary'), - 'class' => '\Drupal\Core\TypedData\Type\Binary', - 'primitive type' => Primitive::BINARY, - ), - 'map' => array( - 'label' => t('Map'), - 'class' => '\Drupal\Core\TypedData\Type\Map', - ), - 'any' => array( - 'label' => t('Any data'), - 'class' => '\Drupal\Core\TypedData\Type\Any', - ), - 'language' => array( - 'label' => t('Language'), - 'description' => t('A language object.'), - 'class' => '\Drupal\Core\TypedData\Type\Language', - ), - 'entity' => array( - 'label' => t('Entity'), - 'description' => t('All kind of entities, e.g. nodes, comments or users.'), - 'class' => '\Drupal\Core\Entity\Field\Type\EntityWrapper', - ), - 'entity_translation' => array( - 'label' => t('Entity translation'), - 'description' => t('A translation of an entity'), - 'class' => '\Drupal\Core\Entity\Field\Type\EntityTranslation', - ), - 'boolean_field' => array( - 'label' => t('Boolean field item'), - 'description' => t('An entity field containing a boolean value.'), - 'class' => '\Drupal\Core\Entity\Field\Type\BooleanItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - ), - 'string_field' => array( - 'label' => t('String field item'), - 'description' => t('An entity field containing a string value.'), - 'class' => '\Drupal\Core\Entity\Field\Type\StringItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - ), - 'email_field' => array( - 'label' => t('E-mail field item'), - 'description' => t('An entity field containing an e-mail value.'), - 'class' => '\Drupal\Core\Entity\Field\Type\EmailItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - ), - 'integer_field' => array( - 'label' => t('Integer field item'), - 'description' => t('An entity field containing an integer value.'), - 'class' => '\Drupal\Core\Entity\Field\Type\IntegerItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - ), - 'date_field' => array( - 'label' => t('Date field item'), - 'description' => t('An entity field containing a date value.'), - 'class' => '\Drupal\Core\Entity\Field\Type\DateItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - ), - 'language_field' => array( - 'label' => t('Language field item'), - 'description' => t('An entity field referencing a language.'), - 'class' => '\Drupal\Core\Entity\Field\Type\LanguageItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - 'constraints' => array( - 'ComplexData' => array( - 'value' => array('Length' => array('max' => 12)), - ), - ), - ), - 'entity_reference_field' => array( - 'label' => t('Entity reference field item'), - 'description' => t('An entity field containing an entity reference.'), - 'class' => '\Drupal\Core\Entity\Field\Type\EntityReferenceItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - ), - 'uri_field' => array( - 'label' => t('URI field item'), - 'description' => t('An entity field containing a URI'), - 'class' => '\Drupal\Core\Entity\Field\Type\UriItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - ), - 'uuid_field' => array( - 'label' => t('UUID field item'), - 'description' => t('An entity field containing a UUID.'), - 'class' => '\Drupal\Core\Entity\Field\Type\UuidItem', - 'list class' => '\Drupal\Core\Entity\Field\Type\Field', - 'constraints' => array( - 'ComplexData' => array( - 'value' => array('Length' => array('max' => 128)), - ), - ), - ), - // Expose each field type as a data type. We add one single entry, which - // will be expanded through plugin derivatives. - 'field_item' => array( - 'derivative' => '\Drupal\Core\Entity\Plugin\DataType\FieldDataTypeDerivative', - ), - ); -} - /** * Menu item access callback - only enabled themes can be accessed. */