diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index 6b7de03..d607cec 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -1192,7 +1192,7 @@ public static function _fieldSqlSchema(FieldConfigInterface $field, array $schem // Define the entity ID schema based on the field definitions. $id_definition = $definitions[$entity_type->getKey('id')]; - if ($id_definition->getType() == 'integer') { + if ($id_definition->getTypeId() == 'integer') { $id_schema = array( 'type' => 'int', 'unsigned' => TRUE, @@ -1212,7 +1212,7 @@ public static function _fieldSqlSchema(FieldConfigInterface $field, array $schem // Define the revision ID schema, default to integer if there is no revision // ID. $revision_id_definition = $entity_type->hasKey('revision_id') ? $definitions[$entity_type->getKey('revision_id')] : NULL; - if (!$revision_id_definition || $revision_id_definition->getType() == 'integer') { + if (!$revision_id_definition || $revision_id_definition->getTypeId() == 'integer') { $revision_id_schema = array( 'type' => 'int', 'unsigned' => TRUE, diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 18b978f..9a30d41 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -99,6 +99,16 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface protected $fieldDefinitions; /** + * Static cache of storage field definitions per entity type. + * + * Elements of the array: + * - $entity_type_id: \Drupal\Core\Field\FieldDefinition[] + * + * @var array + */ + protected $storageFieldDefinitions; + + /** * The root paths. * * @see self::__construct(). @@ -348,8 +358,8 @@ protected function buildBaseFieldDefinitions($entity_type_id) { $base_field_definitions = $class::baseFieldDefinitions($entity_type); $provider = $entity_type->getProvider(); foreach ($base_field_definitions as $definition) { - // @todo Remove this check one FieldDefinitionInterface exposes a proper - // provider setter. See https://drupal.org/node/2225961. + // @todo Remove this check once FieldDefinitionInterface exposes a proper + // provider setter. See https://drupal.org/node/2225961. if ($definition instanceof FieldDefinition) { $definition->setProvider($provider); } @@ -362,8 +372,8 @@ protected function buildBaseFieldDefinitions($entity_type_id) { // Ensure the provider key actually matches the name of the provider // defining the field. foreach ($module_definitions as $field_name => $definition) { - // @todo Remove this check one FieldDefinitionInterface exposes a - // proper provider setter. See https://drupal.org/node/2225961. + // @todo Remove this check once FieldDefinitionInterface exposes a + // proper provider setter. See https://drupal.org/node/2225961. if ($definition instanceof FieldDefinition) { $definition->setProvider($module); } @@ -445,8 +455,8 @@ protected function buildBundleFieldDefinitions($entity_type_id, $bundle, array $ $bundle_field_definitions = $class::bundleFieldDefinitions($entity_type, $bundle, $base_field_definitions); $provider = $entity_type->getProvider(); foreach ($bundle_field_definitions as $definition) { - // @todo Remove this check one FieldDefinitionInterface exposes a proper - // provider setter. See https://drupal.org/node/2225961. + // @todo Remove this check once FieldDefinitionInterface exposes a proper + // provider setter. See https://drupal.org/node/2225961. if ($definition instanceof FieldDefinition) { $definition->setProvider($provider); } @@ -459,8 +469,8 @@ protected function buildBundleFieldDefinitions($entity_type_id, $bundle, array $ // Ensure the provider key actually matches the name of the provider // defining the field. foreach ($module_definitions as $field_name => $definition) { - // @todo Remove this check one FieldDefinitionInterface exposes a - // proper provider setter. See https://drupal.org/node/2225961. + // @todo Remove this check once FieldDefinitionInterface exposes a + // proper provider setter. See https://drupal.org/node/2225961. if ($definition instanceof FieldDefinition) { $definition->setProvider($module); } @@ -486,9 +496,68 @@ protected function buildBundleFieldDefinitions($entity_type_id, $bundle, array $ /** * {@inheritdoc} */ + public function getStorageFieldDefinitions($entity_type_id) { + if (!isset($this->storageFieldDefinitions[$entity_type_id])) { + $base_field_definitions = $this->getBaseFieldDefinitions($entity_type_id); + // Not prepared, try to load from cache. + $cid = 'entity_storage_field_definitions:' . $entity_type_id . ':' . $this->languageManager->getCurrentLanguage()->id; + if ($cache = $this->cache->get($cid)) { + $storage_field_definitions = $cache->data; + } + else { + // Rebuild the definitions and put it into the cache. + $storage_field_definitions = $this->buildStorageFieldDefinitions($entity_type_id); + $this->cache->set($cid, $storage_field_definitions, Cache::PERMANENT, array('entity_types' => TRUE, 'entity_field_info' => TRUE)); + } + $this->storageFieldDefinitions[$entity_type_id] = $base_field_definitions + $storage_field_definitions; + } + return $this->storageFieldDefinitions[$entity_type_id]; + } + + /** + * Builds storage field definitions for an entity type. + * + * @param string $entity_type_id + * The entity type ID. Only entity types that implement + * \Drupal\Core\Entity\ContentEntityInterface are supported + * + * @return \Drupal\Core\Field\StorageFieldDefinitionInterface[] + * An array of storage field definitions, keyed by field name. + */ + protected function buildStorageFieldDefinitions($entity_type_id) { + $entity_type = $this->getDefinition($entity_type_id); + $field_definitions = array(); + + // Retrieve base field definitions from modules. + foreach ($this->moduleHandler->getImplementations('entity_storage_field_info') as $module) { + $module_definitions = $this->moduleHandler->invoke($module, 'entity_storage_field_info', array($entity_type)); + if (!empty($module_definitions)) { + // Ensure the provider key actually matches the name of the provider + // defining the field. + foreach ($module_definitions as $field_name => $definition) { + // @todo Remove this check once FieldDefinitionInterface exposes a + // proper provider setter. See https://drupal.org/node/2225961. + if ($definition instanceof FieldDefinition) { + $definition->setProvider($module); + } + $field_definitions[$field_name] = $definition; + } + } + } + + // Invoke alter hook. + $this->moduleHandler->alter('entity_storage_field_info', $field_definitions, $entity_type); + + return $field_definitions; + } + + /** + * {@inheritdoc} + */ public function clearCachedFieldDefinitions() { $this->baseFieldDefinitions = array(); $this->fieldDefinitions = array(); + $this->storageFieldDefinitions = array(); Cache::deleteTags(array('entity_field_info' => TRUE)); } diff --git a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php index ce964ab..e2e4be7 100644 --- a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php @@ -57,6 +57,28 @@ public function getBaseFieldDefinitions($entity_type_id); public function getFieldDefinitions($entity_type_id, $bundle); /** + * Gets the storage field definitions for a content entity type. + * + * This returns all storage field definitions for base fields and bundle + * fields of an entity type. Note that storage field definitions of a base + * fields equal the full base field definition (i.e. they implement + * \Drupal\Core\Field\FieldDefinitionInterface), while the storage fields for + * bundle fields may implement + * \Drupal\Core\Field\StorageFieldDefinitionInterface only. + * + * @param string $entity_type_id + * The entity type ID. Only entity types that implement + * \Drupal\Core\Entity\ContentEntityInterface are supported. + * + * @return \Drupal\Core\Field\StorageFieldDefinitionInterface[] + * The array of storage field definitions for the entity type, keyed by + * field name. + * + * @see \Drupal\Core\Field\FieldStorageDefinitionInterface + */ + public function getStorageFieldDefinitions($entity_type_id); + + /** * Creates a new access controller instance. * * @param string $entity_type diff --git a/core/lib/Drupal/Core/Field/FieldDefinition.php b/core/lib/Drupal/Core/Field/FieldDefinition.php index e5f4734..ffce944 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinition.php +++ b/core/lib/Drupal/Core/Field/FieldDefinition.php @@ -68,6 +68,37 @@ public static function create($type) { } /** + * Creates a new field definition based upon a field storage definition. + * + * In cases where one needs a field storage definitions to act like full + * field definitions, this creates a new field definition based upon the + * (limited) information available. That way it is possible to use the field + * definition in places where a full field definition is required; e.g., with + * widgets or formatters. + * + * @param StorageFieldDefinitionInterface $definition + * The field storage definition to base the new field definition upon. + * + * @return $this + */ + public static function createFromFieldStorageDefinition(StorageFieldDefinitionInterface $definition) { + return static::create($definition->getTypeId()) + ->setCardinality($definition->getCardinality()) + ->setConstraints($definition->getConstraints()) + ->setCustomStorage($definition->hasCustomStorage()) + ->setDescription($definition->getDescription()) + ->setLabel($definition->getLabel()) + ->setName($definition->getName()) + ->setProvider($definition->getProvider()) + ->setQueryable($definition->isQueryable()) + ->setRequired($definition->isRequired()) + ->setRevisionable($definition->isRevisionable()) + ->setSettings($definition->getSettings()) + ->setTargetEntityTypeId($definition->getTargetEntityTypeId()) + ->setTranslatable($definition->isTranslatable()); + } + + /** * {@inheritdoc} */ public static function createFromItemType($item_type) { @@ -100,7 +131,7 @@ public function setName($name) { /** * {@inheritdoc} */ - public function getType() { + public function getTypeId() { return $this->type; } @@ -443,7 +474,7 @@ public function setTargetEntityTypeId($entity_type_id) { public function getSchema() { if (!isset($this->schema)) { // Get the schema from the field item class. - $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getType()); + $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getTypeId()); $class = $definition['class']; $schema = $class::schema($this); // Fill in default values for optional entries. diff --git a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php index 61a879b..977fce5 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -52,80 +52,7 @@ * based on that abstract definition, even though that abstract definition can * differ from the concrete definition of any particular node's body field. */ -interface FieldDefinitionInterface extends ListDataDefinitionInterface { - - /** - * Value indicating a field accepts an unlimited number of values. - */ - const CARDINALITY_UNLIMITED = -1; - - /** - * Returns the machine name of the field. - * - * This defines how the field data is accessed from the entity. For example, - * if the field name is "foo", then $entity->foo returns its data. - * - * @return string - * The field name. - */ - public function getName(); - - /** - * Returns the field type. - * - * @return string - * The field type, i.e. the id of a field type plugin. For example 'text'. - * - * @see \Drupal\Core\Field\FieldTypePluginManagerInterface - */ - public function getType(); - - /** - * Returns the field settings. - * - * Each field type defines the settings that are meaningful for that type. - * For example, a text field can define a 'max_length' setting, and an image - * field can define a 'alt_field_required' setting. - * - * @return array - * An array of key/value pairs. - */ - public function getSettings(); - - /** - * Returns the value of a given field setting. - * - * @param string $setting_name - * The setting name. - * - * @return mixed - * The setting value. - */ - public function getSetting($setting_name); - - /** - * Returns the name of the provider of this field. - * - * @return string - * The provider name; e.g., the module name. - */ - public function getProvider(); - - /** - * Returns whether the field is translatable. - * - * @return bool - * TRUE if the field is translatable. - */ - public function isTranslatable(); - - /** - * Returns whether the field is revisionable. - * - * @return bool - * TRUE if the field is revisionable. - */ - public function isRevisionable(); +interface FieldDefinitionInterface extends StorageFieldDefinitionInterface, ListDataDefinitionInterface { /** * Returns whether the display for the field can be configured. @@ -174,64 +101,6 @@ public function isDisplayConfigurable($display_context); public function getDisplayOptions($display_context); /** - * Determines whether the field is queryable via QueryInterface. - * - * @return bool - * TRUE if the field is queryable. - */ - public function isQueryable(); - - /** - * Returns the human-readable label for the field. - * - * @return string - * The field label. - */ - public function getLabel(); - - /** - * Returns the human-readable description for the field. - * - * This is displayed in addition to the label in places where additional - * descriptive information is helpful. For example, as help text below the - * form element in entity edit forms. - * - * @return string|null - * The field description, or NULL if no description is available. - */ - public function getDescription(); - - /** - * Returns the maximum number of items allowed for the field. - * - * Possible values are positive integers or - * FieldDefinitionInterface::CARDINALITY_UNLIMITED. - * - * @return integer - * The field cardinality. - */ - public function getCardinality(); - - /** - * Returns whether at least one non-empty item is required for this field. - * - * Currently, required-ness is only enforced at the Form API level in entity - * edit forms, not during direct API saves. - * - * @return bool - * TRUE if the field is required. - */ - public function isRequired(); - - /** - * Returns whether the field can contain multiple items. - * - * @return bool - * TRUE if the field can contain multiple items, FALSE otherwise. - */ - public function isMultiple(); - - /** * Returns the default value for the field in a newly created entity. * * @param \Drupal\Core\Entity\EntityInterface $entity @@ -248,112 +117,4 @@ public function isMultiple(); */ public function getDefaultValue(EntityInterface $entity); - /** - * Gets the definition of a contained property. - * - * @param string $name - * The name of property. - * - * @return \Drupal\Core\TypedData\DataDefinitionInterface|null - * The definition of the property or NULL if the property does not exist. - */ - public function getPropertyDefinition($name); - - /** - * Gets an array of property definitions of contained properties. - * - * @return \Drupal\Core\TypedData\DataDefinitionInterface[] - * An array of property definitions of contained properties, keyed by - * property name. - */ - public function getPropertyDefinitions(); - - /** - * Returns the names of the field's subproperties. - * - * A field is a list of items, and each item can contain one or more - * properties. All items for a given field contain the same property names, - * but the values can be different for each item. - * - * For example, an email field might just contain a single 'value' property, - * while a link field might contain 'title' and 'url' properties, and a text - * field might contain 'value', 'summary', and 'format' properties. - * - * @return array - * The property names. - */ - public function getPropertyNames(); - - /** - * Returns the name of the main property, if any. - * - * Some field items consist mainly of one main property, e.g. the value of a - * text field or the @code target_id @endcode of an entity reference. If the - * field item has no main property, the method returns NULL. - * - * @return string|null - * The name of the value property, or NULL if there is none. - */ - public function getMainPropertyName(); - - /** - * Returns the ID of the type of the entity this field is attached to. - * - * This method should not be confused with EntityInterface::entityType() - * (configurable fields are config entities, and thus implement both - * interfaces): - * - FieldDefinitionInterface::getTargetEntityTypeId() answers "as a field, - * which entity type are you attached to?". - * - EntityInterface::getEntityTypeId() answers "as a (config) entity, what - * is your own entity type". - * - * @return string - * The name of the entity type. - */ - public function getTargetEntityTypeId(); - - /** - * Returns the field schema. - * - * Note that this method returns an empty array for computed fields which have - * no schema. - * - * @return array - * The field schema, as an array of key/value pairs in the format returned - * by hook_field_schema(): - * - columns: An array of Schema API column specifications, keyed by column - * name. This specifies what comprises a single value for a given field. - * No assumptions should be made on how storage backends internally use - * the original column name to structure their storage. - * - indexes: An array of Schema API index definitions. Some storage - * backends might not support indexes. - * - foreign keys: An array of Schema API foreign key definitions. Note, - * however, that depending on the storage backend specified for the field, - * the field data is not necessarily stored in SQL. - */ - public function getSchema(); - - /** - * Returns the field columns, as defined in the field schema. - * - * @return array - * The array of field columns, keyed by column name, in the same format - * returned by getSchema(). - * - * @see \Drupal\Core\Field\FieldDefinitionInterface::getSchema() - */ - public function getColumns(); - - /** - * Returns the storage behavior for this field. - * - * Indicates whether the entity type's storage should take care of storing the - * field values or whether it is handled separately; e.g. by the - * module providing the field. - * - * @return bool - * FALSE if the storage takes care of storing the field, TRUE otherwise. - */ - public function hasCustomStorage(); - } diff --git a/core/lib/Drupal/Core/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Field/FieldItemInterface.php index 58d816c..0a15232 100644 --- a/core/lib/Drupal/Core/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemInterface.php @@ -32,7 +32,7 @@ * * @see \Drupal\Core\Field\FieldDefinition */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition); + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition); /** * Returns the name of the main property, if any. @@ -57,7 +57,7 @@ public static function mainPropertyName(); * * Computed fields having no schema should return an empty array. * - * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition + * @param \Drupal\Core\Field\StorageFieldDefinitionInterface $field_definition * The field definition. * * @return array @@ -81,7 +81,7 @@ public static function mainPropertyName(); * specify another field as related, only existing SQL tables, * such as {taxonomy_term_data}. */ - public static function schema(FieldDefinitionInterface $field_definition); + public static function schema(StorageFieldDefinitionInterface $field_definition); /** * Gets the entity that field belongs to. diff --git a/core/lib/Drupal/Core/Field/FormatterBase.php b/core/lib/Drupal/Core/Field/FormatterBase.php index 1b4287f..29fa270 100644 --- a/core/lib/Drupal/Core/Field/FormatterBase.php +++ b/core/lib/Drupal/Core/Field/FormatterBase.php @@ -84,7 +84,7 @@ public function view(FieldItemListInterface $items) { '#view_mode' => $this->viewMode, '#language' => $items->getLangcode(), '#field_name' => $field_name, - '#field_type' => $this->fieldDefinition->getType(), + '#field_type' => $this->fieldDefinition->getTypeId(), '#field_translatable' => $this->fieldDefinition->isTranslatable(), '#entity_type' => $entity_type, '#bundle' => $entity->bundle(), diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php index d674e75..8440cb4 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php @@ -7,8 +7,8 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -26,7 +26,7 @@ class BooleanItem extends FieldItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('boolean') ->setLabel(t('Boolean value')); @@ -36,7 +36,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DateItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DateItem.php index 7267da0..004100a 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DateItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DateItem.php @@ -7,8 +7,8 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -26,7 +26,7 @@ class DateItem extends FieldItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('date') ->setLabel(t('Date value')); @@ -36,7 +36,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php index cbb79d8..a3d6232 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -35,8 +35,9 @@ public static function defaultSettings() { /** * {@inheritdoc} + */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') ->setLabel(t('Decimal value')); @@ -46,7 +47,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EmailItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EmailItem.php index 4061b12..a5ccb48 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EmailItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EmailItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\TypedData\DataDefinition; @@ -27,7 +27,7 @@ class EmailItem extends FieldItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('email') ->setLabel(t('E-mail value')); @@ -37,7 +37,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index a56b406..090a366 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; use Drupal\Core\Entity\TypedData\EntityDataDefinition; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataReferenceDefinition; @@ -54,7 +54,7 @@ public static function defaultInstanceSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $settings = $field_definition->getSettings(); $target_type_info = \Drupal::entityManager()->getDefinition($settings['target_type']); @@ -97,7 +97,7 @@ public static function mainPropertyName() { /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { $target_type = $field_definition->getSetting('target_type'); $target_type_info = \Drupal::entityManager()->getDefinition($target_type); diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/FloatItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/FloatItem.php index eda49cc..53f0a4a 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/FloatItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/FloatItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -26,7 +26,7 @@ class FloatItem extends NumericItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('float') ->setLabel(t('Float value')); @@ -36,7 +36,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php index f22e060..95236f9 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -26,7 +26,7 @@ class IntegerItem extends NumericItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('integer') ->setLabel(t('Integer value')); @@ -36,7 +36,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php index 9519b8d..f61935a 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Language\Language; use Drupal\Core\TypedData\DataDefinition; @@ -33,7 +33,7 @@ class LanguageItem extends FieldItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') ->setLabel(t('Language code')); @@ -50,7 +50,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php index 7b78006..3a208eb 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\TypedData\DataDefinition; @@ -26,7 +26,7 @@ class MapItem extends FieldItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') ->setLabel(t('Serialized values')); @@ -36,7 +36,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php index 1dfd9f4..9b947d5 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\TypedData\DataDefinition; @@ -37,7 +37,7 @@ public static function defaultSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') ->setLabel(t('Text value')); @@ -47,7 +47,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php index 63964de..998bfa8 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; /** * Defines the 'string_long' field type. @@ -24,7 +24,7 @@ class StringLongItem extends StringItem { /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/TimestampItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/TimestampItem.php index a2d87a6..4d6c345 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/TimestampItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/TimestampItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\TypedData\DataDefinition; @@ -26,7 +26,7 @@ class TimestampItem extends FieldItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('timestamp') ->setLabel(t('Timestamp value')); return $properties; @@ -35,7 +35,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php index d74a85a..031b394 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -38,7 +38,7 @@ public static function defaultSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('uri') ->setLabel(t('URI value')); @@ -48,7 +48,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php index fa31ce7..62d8fe8 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php @@ -79,7 +79,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ); // Set the step for floating point and decimal numbers. - switch ($this->fieldDefinition->getType()) { + switch ($this->fieldDefinition->getTypeId()) { case 'decimal': $element['#step'] = pow(0.1, $field_settings['scale']); break; diff --git a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Field/StorageFieldDefinitionInterface.php similarity index 56% copy from core/lib/Drupal/Core/Field/FieldDefinitionInterface.php copy to core/lib/Drupal/Core/Field/StorageFieldDefinitionInterface.php index 61a879b..a330635 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/StorageFieldDefinitionInterface.php @@ -2,57 +2,23 @@ /** * @file - * Contains \Drupal\Core\Field\FieldDefinitionInterface. + * Contains \Drupal\Core\Field\StorageFieldDefinitionInterface. */ namespace Drupal\Core\Field; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\TypedData\ListDataDefinitionInterface; - /** - * Defines an interface for entity field definitions. - * - * An entity field is a data object that holds the values of a particular field - * for a particular entity (see \Drupal\Core\Field\FieldItemListInterface). For - * example, $node_1->body and $node_2->body contain different data and therefore - * are different field objects. - * - * In contrast, an entity field *definition* is an object that returns - * information *about* a field (e.g., its type and settings) rather than its - * values. As such, if all the information about $node_1->body and $node_2->body - * is the same, then the same field definition object can be used to describe - * both. - * - * It is up to the class implementing this interface to manage where the - * information comes from. For example, field.module provides an implementation - * based on two levels of configuration. It allows the site administrator to add - * custom fields to any entity type and bundle via the "field_config" and - * "field_instance_config" configuration entities. The former for storing - * configuration that is independent of which entity type and bundle the field - * is added to, and the latter for storing configuration that is specific to the - * entity type and bundle. The class that implements "field_instance_config" - * configuration entities also implements this interface, returning information - * from either itself, or from the corresponding "field_config" configuration, - * as appropriate. + * Defines an interface for entity field storage definitions. * - * However, entity base fields, such as $node->title, are not managed by - * field.module and its "field_config"/"field_instance_config" configuration - * entities. Therefore, their definitions are provided by different objects - * based on the class \Drupal\Core\Field\FieldDefinition, which implements this - * interface as well. + * Field storage definitions represent the part of a full field definition (see + * FieldDefintionInterface), which is responsible for defining how the field is + * stored. While field definitions may differ by entity bundle, all of those + * bundle fields have to share the same common field storage definition. Thus, + * field storage definitions can be defined by entity type only. * - * Field definitions may fully define a concrete data object (e.g., - * $node_1->body), or may provide a best-guess definition for a data object that - * might come into existence later. For example, $node_1->body and $node_2->body - * may have different definitions (e.g., if the node types are different). When - * adding the "body" field to a View that can return nodes of different types, - * the View can get a field definition that represents the "body" field - * abstractly, and present Views configuration options to the administrator - * based on that abstract definition, even though that abstract definition can - * differ from the concrete definition of any particular node's body field. + * @see hook_entity_storage_field_info() */ -interface FieldDefinitionInterface extends ListDataDefinitionInterface { +interface StorageFieldDefinitionInterface { /** * Value indicating a field accepts an unlimited number of values. @@ -78,7 +44,7 @@ public function getName(); * * @see \Drupal\Core\Field\FieldTypePluginManagerInterface */ - public function getType(); + public function getTypeId(); /** * Returns the field settings. @@ -87,7 +53,7 @@ public function getType(); * For example, a text field can define a 'max_length' setting, and an image * field can define a 'alt_field_required' setting. * - * @return array + * @return mixed[] * An array of key/value pairs. */ public function getSettings(); @@ -104,14 +70,6 @@ public function getSettings(); public function getSetting($setting_name); /** - * Returns the name of the provider of this field. - * - * @return string - * The provider name; e.g., the module name. - */ - public function getProvider(); - - /** * Returns whether the field is translatable. * * @return bool @@ -128,52 +86,6 @@ public function isTranslatable(); public function isRevisionable(); /** - * Returns whether the display for the field can be configured. - * - * @param string $display_context - * The display context. Either 'view' or 'form'. - * - * @return bool - * TRUE if the display for this field is configurable in the given context. - * If TRUE, the display options returned by getDisplayOptions() may be - * overridden via the respective entity display. - * - * @see \Drupal\Core\Entity\Display\EntityDisplayInterface - */ - public function isDisplayConfigurable($display_context); - - /** - * Returns the default display options for the field. - * - * If the field's display is configurable, the returned display options act - * as default values and may be overridden via the respective entity display. - * Otherwise, the display options will be applied to entity displays as is. - * - * @param string $display_context - * The display context. Either 'view' or 'form'. - * - * @return array|null - * The array of display options for the field, or NULL if the field is not - * displayed. The following key/value pairs may be present: - * - label: (string) Position of the field label. The default 'field' theme - * implementation supports the values 'inline', 'above' and 'hidden'. - * Defaults to 'above'. Only applies to 'view' context. - * - type: (string) The plugin (widget or formatter depending on - * $display_context) to use, or 'hidden'. If not specified or if the - * requested plugin is unknown, the 'default_widget' / 'default_formatter' - * for the field type will be used. - * - settings: (array) Settings for the plugin specified above. The default - * settings for the plugin will be used for settings left unspecified. - * - weight: (float) The weight of the element. Not needed if 'type' is - * 'hidden'. - * The defaults of the various display options above get applied by the used - * entity display. - * - * @see \Drupal\Core\Entity\Display\EntityDisplayInterface - */ - public function getDisplayOptions($display_context); - - /** * Determines whether the field is queryable via QueryInterface. * * @return bool @@ -207,7 +119,7 @@ public function getDescription(); * Possible values are positive integers or * FieldDefinitionInterface::CARDINALITY_UNLIMITED. * - * @return integer + * @return int * The field cardinality. */ public function getCardinality(); @@ -232,23 +144,6 @@ public function isRequired(); public function isMultiple(); /** - * Returns the default value for the field in a newly created entity. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity being created. - * - * @return mixed - * The default value for the field, as accepted by - * Drupal\field\Plugin\Core\Entity\Field::setValue(). This can be either: - * - a literal, in which case it will be assigned to the first property of - * the first item. - * - a numerically indexed array of items, each item being a property/value - * array. - * - NULL or array() for no default value. - */ - public function getDefaultValue(EntityInterface $entity); - - /** * Gets the definition of a contained property. * * @param string $name @@ -279,7 +174,7 @@ public function getPropertyDefinitions(); * while a link field might contain 'title' and 'url' properties, and a text * field might contain 'value', 'summary', and 'format' properties. * - * @return array + * @return string[] * The property names. */ public function getPropertyNames(); @@ -318,7 +213,7 @@ public function getTargetEntityTypeId(); * Note that this method returns an empty array for computed fields which have * no schema. * - * @return array + * @return array[] * The field schema, as an array of key/value pairs in the format returned * by hook_field_schema(): * - columns: An array of Schema API column specifications, keyed by column @@ -336,7 +231,7 @@ public function getSchema(); /** * Returns the field columns, as defined in the field schema. * - * @return array + * @return array[] * The array of field columns, keyed by column name, in the same format * returned by getSchema(). * @@ -345,6 +240,44 @@ public function getSchema(); public function getColumns(); /** + * Returns an array of validation constraints. + * + * See \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details. + * + * @return array[] + * An array of validation constraint definitions, keyed by constraint name. + * Each constraint definition can be used for instantiating + * \Symfony\Component\Validator\Constraint objects. + * + * @see \Symfony\Component\Validator\Constraint + */ + public function getConstraints(); + + /** + * Returns a validation constraint. + * + * See \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details. + * + * @param string $constraint_name + * The name of the the constraint, i.e. its plugin id. + * + * @return array + * A validation constraint definition which can be used for instantiating a + * \Symfony\Component\Validator\Constraint object. + * + * @see \Symfony\Component\Validator\Constraint + */ + public function getConstraint($constraint_name); + + /** + * Returns the name of the provider of this field. + * + * @return string + * The provider name; e.g., the module name. + */ + public function getProvider(); + + /** * Returns the storage behavior for this field. * * Indicates whether the entity type's storage should take care of storing the diff --git a/core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php b/core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php index dbf81c6..6ed9ba7 100644 --- a/core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php +++ b/core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php @@ -51,7 +51,7 @@ public static function createFromDataType($data_type) { * @return static */ public static function create($field_definition) { - $definition['type'] = 'field_item:' . $field_definition->getType(); + $definition['type'] = 'field_item:' . $field_definition->getTypeId(); $item_definition = new static($definition); $item_definition->fieldDefinition = $field_definition; return $item_definition; diff --git a/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php index 33ea5d8..c8dfde1 100644 --- a/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -118,7 +118,7 @@ public function form(FieldItemListInterface $items, array &$form, array &$form_s '#parents' => array_merge($parents, array($field_name . '_wrapper')), '#attributes' => array( 'class' => array( - 'field-type-' . drupal_html_class($this->fieldDefinition->getType()), + 'field-type-' . drupal_html_class($this->fieldDefinition->getTypeId()), 'field-name-' . drupal_html_class($field_name), 'field-widget-' . drupal_html_class($this->getPluginId()), ), diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 9ee58fc..47d4409 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -193,7 +193,7 @@ function comment_count_unpublished() { * Implements hook_ENTITY_TYPE_insert() for 'field_instance_config'. */ function comment_field_instance_config_insert(FieldInstanceConfigInterface $instance) { - if ($instance->getType() == 'comment' && !$instance->isSyncing()) { + if ($instance->getTypeId() == 'comment' && !$instance->isSyncing()) { \Drupal::service('comment.manager')->addBodyField($instance->entity_type, $instance->getName()); } } @@ -202,7 +202,7 @@ function comment_field_instance_config_insert(FieldInstanceConfigInterface $inst * Implements hook_ENTITY_TYPE_create() for 'field_instance_config'. */ function comment_field_instance_config_create(FieldInstanceConfigInterface $instance) { - if ($instance->getType() == 'comment' && !$instance->isSyncing()) { + if ($instance->getTypeId() == 'comment' && !$instance->isSyncing()) { // Assign default values for the field instance. if (!isset($instance->default_value)) { $instance->default_value = array(); @@ -223,7 +223,7 @@ function comment_field_instance_config_create(FieldInstanceConfigInterface $inst * Implements hook_ENTITY_TYPE_update() for 'field_instance_config'. */ function comment_field_instance_config_update(FieldInstanceConfigInterface $instance) { - if ($instance->getType() == 'comment') { + if ($instance->getTypeId() == 'comment') { // Comment field settings also affects the rendering of *comment* entities, // not only the *commented* entities. \Drupal::entityManager()->getViewBuilder('comment')->resetCache(); @@ -234,7 +234,7 @@ function comment_field_instance_config_update(FieldInstanceConfigInterface $inst * Implements hook_ENTITY_TYPE_delete() for 'field_config'. */ function comment_field_config_delete(FieldConfigInterface $field) { - if ($field->getType() == 'comment') { + if ($field->getTypeId() == 'comment') { // Delete all fields and displays attached to the comment bundle. entity_invoke_bundle_hook('delete', 'comment', $field->entity_type . '__' . $field->getName()); } @@ -244,7 +244,7 @@ function comment_field_config_delete(FieldConfigInterface $field) { * Implements hook_ENTITY_TYPE_delete() for 'field_instance_config'. */ function comment_field_instance_config_delete(FieldInstanceConfigInterface $instance) { - if ($instance->getType() == 'comment') { + if ($instance->getTypeId() == 'comment') { // Delete all comments that used by the entity bundle. $comments = db_query("SELECT cid FROM {comment} WHERE entity_type = :entity_type AND field_id = :field_id", array( ':entity_type' => $instance->getEntityTypeId(), diff --git a/core/modules/comment/lib/Drupal/comment/CommentFieldNameItem.php b/core/modules/comment/lib/Drupal/comment/CommentFieldNameItem.php index 0f6eae2..5a912c8 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFieldNameItem.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFieldNameItem.php @@ -7,7 +7,7 @@ namespace Drupal\comment; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\Plugin\Field\FieldType\StringItem; use Drupal\Core\TypedData\DataDefinition; @@ -19,7 +19,7 @@ class CommentFieldNameItem extends StringItem { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') ->setLabel(t('String value')) ->setClass('\Drupal\comment\CommentFieldNameValue') diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php index 78bdf82..9f67867 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php @@ -7,7 +7,7 @@ namespace Drupal\comment\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Session\AnonymousUserSession; @@ -51,7 +51,7 @@ public static function defaultInstanceSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['status'] = DataDefinition::create('integer') ->setLabel(t('Comment status value')); @@ -79,7 +79,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'status' => array( diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 96b8d3c..7122d9c 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -23,7 +23,7 @@ function content_translation_field_sync_widget(FieldDefinitionInterface $field) { $element = array(); - $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType()); + $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getTypeId()); $column_groups = $definition['column_groups']; if (!empty($column_groups) && count($column_groups) > 1) { $options = array(); diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index dc405b9..bace39d 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -751,9 +751,9 @@ function content_translation_form_field_ui_field_edit_form_submit($form, array & * Implements hook_form_FORM_ID_alter() for 'field_ui_field_instance_edit_form'. */ function content_translation_form_field_ui_field_instance_edit_form_alter(array &$form, array &$form_state, $form_id) { - if ($form['#field']->isTranslatable()) { + if ($form_state['instance']->isTranslatable()) { module_load_include('inc', 'content_translation', 'content_translation.admin'); - $element = content_translation_field_sync_widget($form['#field']); + $element = content_translation_field_sync_widget($form_state['instance']); if ($element) { $form['instance']['settings']['translation_sync'] = $element; } diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php index e600079..efc8f25 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php @@ -7,7 +7,7 @@ namespace Drupal\datetime\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\PrepareCacheInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Field\FieldItemBase; @@ -48,7 +48,7 @@ public static function defaultSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('datetime_iso8601') ->setLabel(t('Date value')); @@ -65,7 +65,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php index 13bf441..99eedad 100644 --- a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php +++ b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php @@ -242,7 +242,7 @@ protected function simplify(array &$form, array &$form_state) { */ protected function getChangedFieldName(ContentEntityInterface $entity) { foreach ($entity->getFieldDefinitions() as $field) { - if ($field->getType() == 'changed') { + if ($field->getTypeId() == 'changed') { return $field->getName(); } } diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index dd1bfa0..b79985f 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -261,7 +261,7 @@ protected function init() { $this->hidden[$name] = TRUE; } elseif ($options) { - $this->content[$name] = $this->pluginManager->prepareConfiguration($definition->getType(), $options); + $this->content[$name] = $this->pluginManager->prepareConfiguration($definition->getTypeId(), $options); } // Note: (base) fields that do not specify display options are not // tracked in the display at all, in order to avoid cluttering the @@ -305,7 +305,7 @@ public function setComponent($name, array $options = array()) { // For a field, fill in default options. if ($field_definition = $this->getFieldDefinition($name)) { - $options = $this->pluginManager->prepareConfiguration($field_definition->getType(), $options); + $options = $this->pluginManager->prepareConfiguration($field_definition->getTypeId(), $options); } $this->content[$name] = $options; diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/lib/Drupal/entity_reference/ConfigurableEntityReferenceItem.php index 550f3d7..c355484 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/ConfigurableEntityReferenceItem.php @@ -8,7 +8,7 @@ namespace Drupal\entity_reference; use Drupal\Component\Utility\String; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\AllowedValuesInterface; @@ -97,7 +97,7 @@ public function getSettableOptions(AccountInterface $account = NULL) { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $settings = $field_definition->getSettings(); $target_type = $settings['target_type']; @@ -136,7 +136,7 @@ public function getConstraints() { /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { $schema = parent::schema($field_definition); $target_type = $field_definition->getSetting('target_type'); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php index 2383ba6..f86393e 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php @@ -79,7 +79,7 @@ public function handleAutocomplete(Request $request, $type, $field_name, $entity $field_definition = $definitions[$field_name]; $access_controller = $this->entityManager()->getAccessController($entity_type); - if ($field_definition->getType() != 'entity_reference' || !$access_controller->fieldAccess('edit', $field_definition)) { + if ($field_definition->getTypeId() != 'entity_reference' || !$access_controller->fieldAccess('edit', $field_definition)) { throw new AccessDeniedHttpException(); } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index db35e40..3f91dab 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -174,6 +174,16 @@ function field_system_info_alter(&$info, Extension $file, $type) { } /** + * Implements hook_entity_storage_field_info(). + */ +function field_entity_storage_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) { + // Expose storage fields for all exposed bundle fields. + if ($entity_type->isFieldable()) { + return Field::fieldInfo()->getFields(); + } +} + +/** * Implements hook_entity_bundle_field_info(). */ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index c142163..f9d0f95 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -112,7 +112,7 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { $data = array(); // Check the field type is available. - if (!\Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType())) { + if (!\Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getTypeId())) { return $data; } // Check the field has instances. diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php index 11c4f0d..e5de951 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php @@ -9,10 +9,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\Entity\ConfigEntityBase; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Field\FieldDefinition; -use Drupal\Core\Field\TypedData\FieldItemDataDefinition; use Drupal\field\FieldException; use Drupal\field\FieldConfigInterface; @@ -182,13 +179,6 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface { protected $propertyDefinitions; /** - * The data definition of a field item. - * - * @var \Drupal\Core\TypedData\DataDefinition - */ - protected $itemDefinition; - - /** * Constructs a FieldConfig object. * * @param array $values @@ -521,7 +511,7 @@ public function getName() { /** * {@inheritdoc} */ - public function getType() { + public function getTypeId() { return $this->type; } @@ -536,8 +526,7 @@ public function getSettings() { $field_type_manager = \Drupal::service('plugin.manager.field.field_type'); $settings = $field_type_manager->getDefaultSettings($this->type); - $instance_settings = $field_type_manager->getDefaultInstanceSettings($this->type); - return $this->settings + $settings + $instance_settings; + return $this->settings + $settings; } /** @@ -640,26 +629,6 @@ public function isLocked() { /** * {@inheritdoc} */ - public function getDefaultValue(EntityInterface $entity) { } - - /** - * {@inheritdoc} - */ - public function isDisplayConfigurable($context) { - return TRUE; - } - - /** - * {@inheritdoc} - */ - public function getDisplayOptions($display_context) { - // Hide configurable fields by default. - return array('type' => 'hidden'); - } - - /** - * {@inheritdoc} - */ public function getTargetEntityTypeId() { return $this->entity_type; } @@ -739,62 +708,6 @@ public function __wakeup() { /** * {@inheritdoc} */ - public static function createFromDataType($type) { - // Forward to the field definition class for creating new data definitions - // via the typed manager. - return FieldDefinition::createFromDataType($type); - } - - /** - * {@inheritdoc} - */ - public static function createFromItemType($item_type) { - // Forward to the field definition class for creating new data definitions - // via the typed manager. - return FieldDefinition::createFromItemType($item_type); - } - - /** - * {@inheritdoc} - */ - public function getDataType() { - return 'list'; - } - - /** - * {@inheritdoc} - */ - public function isList() { - return TRUE; - } - - /** - * {@inheritdoc} - */ - public function isReadOnly() { - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function isComputed() { - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function getClass() { - // Derive list class from the field type. - $type_definition = \Drupal::service('plugin.manager.field.field_type') - ->getDefinition($this->getType()); - return $type_definition['list_class']; - } - - /** - * {@inheritdoc} - */ public function getConstraints() { return array(); } @@ -809,17 +722,6 @@ public function getConstraint($constraint_name) { /** * {@inheritdoc} */ - public function getItemDefinition() { - if (!isset($this->itemDefinition)) { - $this->itemDefinition = FieldItemDataDefinition::create($this) - ->setSettings($this->getSettings()); - } - return $this->itemDefinition; - } - - /** - * {@inheritdoc} - */ public function getPropertyDefinition($name) { if (!isset($this->propertyDefinitions)) { $this->getPropertyDefinitions(); @@ -857,19 +759,11 @@ public function getMainPropertyName() { /** * Helper to retrieve the field item class. - * - * @todo: Remove once getClass() adds in defaults. See - * https://drupal.org/node/2116341. */ protected function getFieldItemClass() { - if ($class = $this->getItemDefinition()->getClass()) { - return $class; - } - else { - $type_definition = \Drupal::typedDataManager() - ->getDefinition($this->getItemDefinition()->getDataType()); - return $type_definition['class']; - } + $type_definition = \Drupal::typedDataManager() + ->getDefinition('field_item:' . $this->getTypeId()); + return $type_definition['class']; } } diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index 3eea9cb..7f8513b 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -490,7 +490,7 @@ public function getName() { /** * {@inheritdoc} */ - public function getType() { + public function getTypeId() { return $this->field->type; } @@ -717,7 +717,10 @@ public function isComputed() { * {@inheritdoc} */ public function getClass() { - return $this->field->getClass(); + // Derive list class from the field type. + $type_definition = \Drupal::service('plugin.manager.field.field_type') + ->getDefinition($this->getTypeId()); + return $type_definition['list_class']; } /** diff --git a/core/modules/field/lib/Drupal/field/FieldConfigInterface.php b/core/modules/field/lib/Drupal/field/FieldConfigInterface.php index 1b63629..785605e 100644 --- a/core/modules/field/lib/Drupal/field/FieldConfigInterface.php +++ b/core/modules/field/lib/Drupal/field/FieldConfigInterface.php @@ -8,12 +8,12 @@ namespace Drupal\field; use Drupal\Core\Config\Entity\ConfigEntityInterface; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; /** * Provides an interface defining a field entity. */ -interface FieldConfigInterface extends ConfigEntityInterface, FieldDefinitionInterface { +interface FieldConfigInterface extends ConfigEntityInterface, StorageFieldDefinitionInterface { /** * Returns the list of bundles where the field has instances. diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 808a31b..af17a99 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -523,7 +523,7 @@ function getInstance($entity_type, $bundle, $field_name) { */ public function prepareField(FieldConfigInterface $field) { // Make sure all expected field settings are present. - $field->settings += $this->fieldTypeManager->getDefaultSettings($field->getType()); + $field->settings += $this->fieldTypeManager->getDefaultSettings($field->getTypeId()); return $field; } @@ -539,7 +539,7 @@ public function prepareField(FieldConfigInterface $field) { */ public function prepareInstance(FieldInstanceConfigInterface $instance) { // Make sure all expected instance settings are present. - $instance->settings += $this->fieldTypeManager->getDefaultInstanceSettings($instance->getType()); + $instance->settings += $this->fieldTypeManager->getDefaultInstanceSettings($instance->getTypeId()); return $instance; } diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 6620e3f..5143961 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Field\FieldDefinition; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\field\Field as FieldHelper; use Drupal\Core\Entity\ContentEntityDatabaseStorage; @@ -40,9 +41,13 @@ class Field extends FieldPluginBase { public $items = array(); /** - * The field information as returned by field_info_field(). + * The field definition to use. * - * @var \Drupal\field\FieldConfigInterface + * A field storage definition turned into a field definition, so it can be + * used with widgets and formatters. See + * FieldDefinition::createFromFieldStorageDefinition(). + * + * @var \Drupal\Core\Field\FieldDefinitionInterface */ public $field_info; @@ -139,7 +144,8 @@ public static function create(ContainerInterface $container, array $configuratio public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); - $this->field_info = FieldHelper::fieldInfo()->getField($this->definition['entity_type'], $this->definition['field_name']); + $storage_field_definition = FieldHelper::fieldInfo()->getField($this->definition['entity_type'], $this->definition['field_name']); + $this->field_info = FieldDefinition::createFromFieldStorageDefinition($storage_field_definition); $this->multiple = FALSE; $this->limit_values = FALSE; @@ -322,7 +328,7 @@ protected function defineOptions() { // defineOptions runs before init/construct, so no $this->field_info $field = field_info_field($this->definition['entity_type'], $this->definition['field_name']); - $field_type = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType()); + $field_type = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getTypeId()); $column_names = array_keys($field->getColumns()); $default_column = ''; // Try to determine a sensible default. @@ -394,7 +400,7 @@ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); $field = $this->field_info; - $formatters = $this->formatterPluginManager->getOptions($field->getType()); + $formatters = $this->formatterPluginManager->getOptions($field->getTypeId()); $column_names = array_keys($field->getColumns()); // If this is a multiple value field, add its options. diff --git a/core/modules/field/tests/modules/field_test/field_test.field.inc b/core/modules/field/tests/modules/field_test/field_test.field.inc index 79b57a3..a7a988c 100644 --- a/core/modules/field/tests/modules/field_test/field_test.field.inc +++ b/core/modules/field/tests/modules/field_test/field_test.field.inc @@ -23,7 +23,7 @@ function field_test_field_widget_info_alter(&$info) { * Implements hook_field_config_update_forbid(). */ function field_test_field_config_update_forbid(FieldConfigInterface $field, FieldConfigInterface $prior_field) { - if ($field->getType() == 'test_field' && $field->getSetting('unchangeable') != $prior_field->getSetting('unchangeable')) { + if ($field->getTypeId() == 'test_field' && $field->getSetting('unchangeable') != $prior_field->getSetting('unchangeable')) { throw new FieldConfigUpdateForbiddenException("field_test 'unchangeable' setting cannot be changed'"); } } diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/HiddenTestItem.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/HiddenTestItem.php index 700efde..a2dca38 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/HiddenTestItem.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/HiddenTestItem.php @@ -7,7 +7,7 @@ namespace Drupal\field_test\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -26,8 +26,9 @@ class HiddenTestItem extends TestItem { /** * {@inheritdoc} + */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('integer') ->setLabel(t('Test integer value')); diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/ShapeItem.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/ShapeItem.php index 58985b8..42608df 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/ShapeItem.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/ShapeItem.php @@ -7,7 +7,7 @@ namespace Drupal\field_test\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Field\FieldItemBase; @@ -36,7 +36,7 @@ public static function defaultSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['shape'] = DataDefinition::create('string') ->setLabel(t('Shape')); @@ -49,7 +49,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { $foreign_keys = array(); // The 'foreign keys' key is not always used in tests. if ($field_definition->getSetting('foreign_key_name')) { diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/TestItem.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/TestItem.php index b3326ef..5fe2dd4 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/TestItem.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/TestItem.php @@ -7,7 +7,7 @@ namespace Drupal\field_test\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\PrepareCacheInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Field\FieldItemBase; @@ -49,7 +49,7 @@ public static function defaultInstanceSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('integer') ->setLabel(t('Test integer value')); @@ -59,7 +59,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php index 2deca15..51215de 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php @@ -268,7 +268,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent '#region_callback' => array($this, 'getRowRegion'), '#js_settings' => array( 'rowHandler' => 'field', - 'defaultPlugin' => $this->getDefaultPlugin($field_definition->getType()), + 'defaultPlugin' => $this->getDefaultPlugin($field_definition->getTypeId()), ), 'human_name' => array( '#markup' => check_plain($label), @@ -305,7 +305,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent '#type' => 'select', '#title' => $this->t('Plugin for @title', array('@title' => $label)), '#title_display' => 'invisible', - '#options' => $this->getPluginOptions($field_definition->getType()), + '#options' => $this->getPluginOptions($field_definition->getTypeId()), '#default_value' => $display_options ? $display_options['type'] : 'hidden', '#parents' => array('fields', $field_name, 'type'), '#attributes' => array('class' => array('field-plugin-type')), diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php index 3739368..b473168 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php @@ -145,7 +145,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceConfigIn // Build the non-configurable field values. $form['field']['field_name'] = array('#type' => 'value', '#value' => $field->getName()); - $form['field']['type'] = array('#type' => 'value', '#value' => $field->getType()); + $form['field']['type'] = array('#type' => 'value', '#value' => $field->getTypeId()); $form['field']['module'] = array('#type' => 'value', '#value' => $field->module); // Add settings provided by the field module. The field module is diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 3843be9..0093e27 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1921,7 +1921,7 @@ function file_get_file_references(File $file, $field = NULL, $age = EntityStorag foreach ($return as $field_name => $data) { foreach (array_keys($data) as $entity_type_id) { $current_field = field_info_field($entity_type_id, $field_name); - if (($field_type && $current_field->getType() != $field_type) || ($field && $field->uuid() != $current_field->uuid())) { + if (($field_type && $current_field->getTypeId() != $field_type) || ($field && $field->uuid() != $current_field->uuid())) { unset($return[$field_name][$entity_type_id]); } } diff --git a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php index 7e66420..4342754 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php +++ b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php @@ -7,7 +7,7 @@ namespace Drupal\file\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\Core\TypedData\DataDefinition; @@ -52,7 +52,7 @@ public static function defaultInstanceSettings() { /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'target_id' => array( @@ -90,7 +90,7 @@ public static function schema(FieldDefinitionInterface $field_definition) { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties = parent::propertyDefinitions($field_definition); $properties['display'] = DataDefinition::create('boolean') diff --git a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php index 7a93634..7c45449 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php @@ -7,7 +7,7 @@ namespace Drupal\image\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\file\Plugin\Field\FieldType\FileItem; @@ -83,7 +83,7 @@ public static function defaultInstanceSettings() { /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'target_id' => array( @@ -130,7 +130,7 @@ public static function schema(FieldDefinitionInterface $field_definition) { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties = parent::propertyDefinitions($field_definition); $properties['alt'] = DataDefinition::create('string') diff --git a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php index 58a5826..b3a4ce8 100644 --- a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php +++ b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php @@ -8,7 +8,7 @@ namespace Drupal\link\Plugin\Field\FieldType; use Drupal\Core\Field\FieldItemBase; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\MapDataDefinition; @@ -37,7 +37,7 @@ public static function defaultInstanceSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['url'] = DataDefinition::create('uri') ->setLabel(t('URL')); @@ -53,7 +53,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'url' => array( diff --git a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityContentBase.php index 4feee21..25030dc 100644 --- a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityContentBase.php @@ -84,7 +84,7 @@ public function import(Row $row, array $old_destination_id_values = array()) { } } foreach ($instances as $field_name => $instance) { - $field_type = $instance->getType(); + $field_type = $instance->getTypeId(); if ($this->migrateEntityFieldPluginManager->getDefinition($field_type)) { $destination_value = $this->migrateEntityFieldPluginManager->createInstance($field_type)->import($instance, $row->getDestinationProperty($field_name)); // @TODO: check for NULL return? Add an unset to $row? Maybe needed in diff --git a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListBooleanItem.php b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListBooleanItem.php index 76de3b7..7503a5d 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListBooleanItem.php +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListBooleanItem.php @@ -8,7 +8,7 @@ namespace Drupal\options\Plugin\Field\FieldType; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\AllowedValuesInterface; @@ -68,7 +68,7 @@ public function getSettableOptions(AccountInterface $account = NULL) { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('boolean') ->setLabel(t('Boolean value')); @@ -78,7 +78,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListFloatItem.php b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListFloatItem.php index b3f7271..5218429 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListFloatItem.php +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListFloatItem.php @@ -7,7 +7,7 @@ namespace Drupal\options\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -26,7 +26,7 @@ class ListFloatItem extends ListItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('float') ->setLabel(t('Float value')); @@ -36,7 +36,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListIntegerItem.php b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListIntegerItem.php index cc506d4..3fc61fc 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListIntegerItem.php +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListIntegerItem.php @@ -7,7 +7,7 @@ namespace Drupal\options\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -26,7 +26,7 @@ class ListIntegerItem extends ListItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('integer') ->setLabel(t('Integer value')); @@ -36,7 +36,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListTextItem.php b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListTextItem.php index 6180368..eefac28 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListTextItem.php +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListTextItem.php @@ -7,7 +7,7 @@ namespace Drupal\options\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -26,7 +26,7 @@ class ListTextItem extends ListItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $constraints = array('Length' => array('max' => 255)); $properties['value'] = DataDefinition::create('string') ->setLabel(t('Text value')) @@ -38,7 +38,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/path/lib/Drupal/path/Plugin/Field/FieldType/PathItem.php b/core/modules/path/lib/Drupal/path/Plugin/Field/FieldType/PathItem.php index 9e8c3fd..154d31e 100644 --- a/core/modules/path/lib/Drupal/path/Plugin/Field/FieldType/PathItem.php +++ b/core/modules/path/lib/Drupal/path/Plugin/Field/FieldType/PathItem.php @@ -7,7 +7,7 @@ namespace Drupal\path\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\TypedData\DataDefinition; @@ -26,7 +26,7 @@ class PathItem extends FieldItemBase { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['alias'] = DataDefinition::create('string') ->setLabel(t('Path alias')); $properties['pid'] = DataDefinition::create('string') @@ -37,7 +37,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array(); } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutPathItem.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutPathItem.php index 10dbed5..82634f7 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutPathItem.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutPathItem.php @@ -7,7 +7,7 @@ namespace Drupal\shortcut; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\Plugin\Field\FieldType\StringItem; use Drupal\Core\TypedData\DataDefinition; @@ -19,7 +19,7 @@ class ShortcutPathItem extends StringItem { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') ->setLabel(t('String value')) ->setComputed(TRUE) diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 315d55d..174f071 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -706,6 +706,9 @@ function hook_entity_base_field_info_alter(&$fields, \Drupal\Core\Entity\EntityT /** * Provides field definitions for a specific bundle within an entity type. * + * Bundle fields either have to override an existing base field, or need to + * provide a storage field via hook_entity_storage_field_info(). + * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. * @param string $bundle @@ -718,6 +721,8 @@ function hook_entity_base_field_info_alter(&$fields, \Drupal\Core\Entity\EntityT * * @see hook_entity_base_field_info() * @see hook_entity_base_field_info_alter() + * @see hook_entity_storage_field_info() + * @see hook_entity_storage_field_info_alter() * @see hook_entity_bundle_field_info_alter() * @see \Drupal\Core\Field\FieldDefinitionInterface * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() @@ -756,6 +761,43 @@ function hook_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\Entit } /** + * Provides storage field definitions for a content entity type. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * + * @return \Drupal\Core\Field\StorageFieldDefinitionInterface[] + * An array of storage field definitions, keyed by field name. + * + * @see hook_entity_storage_field_info_alter() + * @see \Drupal\Core\Field\FieldStorageDefinitionInterface + * @see \Drupal\Core\Entity\EntityManagerInterface::getStorageFieldDefinitions() + */ +function hook_entity_storage_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) { + // Expose storage fields for all exposed bundle fields. + if ($entity_type->isFieldable()) { + return Field::fieldInfo()->getFields(); + } +} + +/** + * Alters storage field definitions for a content entity type. + * + * @param \Drupal\Core\Field\StorageFieldDefinitionInterface[] $fields + * The array of storage field definitions for the entity type. + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * + * @see hook_entity_storage_field_info() + */ +function hook_entity_storage_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type) { + // Alter the max_length setting. + if ($entity_type->id() == 'node' && !empty($fields['mymodule_text'])) { + $fields['mymodule_text']->setSetting('max_length', 128); + } +} + +/** * Alter entity operations. * * @param array $operations diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 61c8c87..227b2d2 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -355,9 +355,9 @@ protected function checkIntrospection($entity_type) { // Test getting metadata upfront. The entity types used for this test have // a default bundle that is the same as the entity type. $definitions = \Drupal::entityManager()->getFieldDefinitions($entity_type, $entity_type); - $this->assertEqual($definitions['name']->getType(), 'string', $entity_type .': Name field found.'); - $this->assertEqual($definitions['user_id']->getType(), 'entity_reference', $entity_type .': User field found.'); - $this->assertEqual($definitions['field_test_text']->getType(), 'text', $entity_type .': Test-text-field field found.'); + $this->assertEqual($definitions['name']->getTypeId(), 'string', $entity_type .': Name field found.'); + $this->assertEqual($definitions['user_id']->getTypeId(), 'entity_reference', $entity_type .': User field found.'); + $this->assertEqual($definitions['field_test_text']->getTypeId(), 'text', $entity_type .': Test-text-field field found.'); // Test deriving further metadata. $this->assertTrue($definitions['name'] instanceof FieldDefinitionInterface); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php index ab1db7d..cf96c30 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php @@ -110,7 +110,7 @@ public function autocomplete(Request $request, $entity_type, $field_name) { $tags_typed = $request->query->get('q'); // Make sure the field exists and is a taxonomy field. - if (!($field = $this->fieldInfo->getField($entity_type, $field_name)) || $field->getType() !== 'taxonomy_term_reference') { + if (!($field = $this->fieldInfo->getField($entity_type, $field_name)) || $field->getTypeId() !== 'taxonomy_term_reference') { // Error string. The JavaScript handler will realize this is not JSON and // will display it as debugging information. return new Response(t('Taxonomy field @field_name not found.', array('@field_name' => $field_name)), 403); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php index eaa2103..9a444c8 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php @@ -7,7 +7,7 @@ namespace Drupal\taxonomy\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\AllowedValuesInterface; @@ -94,7 +94,7 @@ public function getSettableOptions(AccountInterface $account = NULL) { /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'target_id' => array( diff --git a/core/modules/telephone/lib/Drupal/telephone/Plugin/Field/FieldType/TelephoneItem.php b/core/modules/telephone/lib/Drupal/telephone/Plugin/Field/FieldType/TelephoneItem.php index 6be9dff..c9a8268 100644 --- a/core/modules/telephone/lib/Drupal/telephone/Plugin/Field/FieldType/TelephoneItem.php +++ b/core/modules/telephone/lib/Drupal/telephone/Plugin/Field/FieldType/TelephoneItem.php @@ -8,7 +8,7 @@ namespace Drupal\telephone\Plugin\Field\FieldType; use Drupal\Core\Field\FieldItemBase; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -27,7 +27,7 @@ class TelephoneItem extends FieldItemBase { /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( @@ -42,7 +42,7 @@ public static function schema(FieldDefinitionInterface $field_definition) { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') ->setLabel(t('Telephone number')); diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItem.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItem.php index 49ca7f1..1a6eba2 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItem.php @@ -7,7 +7,7 @@ namespace Drupal\text\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; /** * Plugin implementation of the 'text' field type. @@ -34,7 +34,7 @@ public static function defaultSettings() { /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php index fe704c2..fb2d8de 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php @@ -8,7 +8,7 @@ namespace Drupal\text\Plugin\Field\FieldType; use Drupal\Core\Field\FieldItemBase; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\Field\PrepareCacheInterface; use Drupal\Core\TypedData\DataDefinition; @@ -29,7 +29,7 @@ public static function defaultInstanceSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') ->setLabel(t('Text value')); diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextLongItem.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextLongItem.php index 1cf0385..db2f8d6 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextLongItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextLongItem.php @@ -7,7 +7,7 @@ namespace Drupal\text\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; /** * Plugin implementation of the 'text_long' field type. @@ -25,7 +25,7 @@ class TextLongItem extends TextItemBase { /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php index 8cb505f..ae8cb0e 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php @@ -7,7 +7,7 @@ namespace Drupal\text\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\StorageFieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -36,7 +36,7 @@ public static function defaultInstanceSettings() { /** * {@inheritdoc} */ - public static function propertyDefinitions(FieldDefinitionInterface $field_definition) { + public static function propertyDefinitions(StorageFieldDefinitionInterface $field_definition) { $properties = parent::propertyDefinitions($field_definition); $properties['summary'] = DataDefinition::create('string') @@ -55,7 +55,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function schema(FieldDefinitionInterface $field_definition) { + public static function schema(StorageFieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index b16008c..a0a72de 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -476,6 +476,33 @@ public function testGetFieldDefinitions() { } /** + * Tests the getStorageFieldDefinitions() method. + * + * @covers ::getStorageFieldDefinitions() + */ + public function testGetStorageFieldDefinitions() { + $field_definition = $this->setUpEntityWithFieldDefinition(TRUE); + $storage_field_definition = $this->getMock('\Drupal\Core\Field\FieldStorageDefinitionInterface'); + $storage_field_definition->expects($this->any()) + ->method('getName') + ->will($this->returnValue('storage_field')); + + $this->moduleHandler->expects($this->any()) + ->method('getImplementations') + ->will($this->returnValue(array('phpunit'))); + + $this->moduleHandler->expects($this->any()) + ->method('invoke') + ->will($this->returnValue(array('storage_field' => $storage_field_definition))); + + $expected = array( + 'id' => $field_definition, + 'storage_field' => $storage_field_definition, + ); + $this->assertSame($expected, $this->entityManager->getStorageFieldDefinitions('test_entity_type')); + } + + /** * Tests the getBaseFieldDefinitions() method with caching. * * @covers ::getBaseFieldDefinitions() @@ -501,7 +528,6 @@ public function testGetBaseFieldDefinitionsWithCaching() { $this->assertSame($expected, $this->entityManager->getBaseFieldDefinitions('test_entity_type')); } - /** * Tests the getFieldDefinitions() method with caching. * @@ -537,6 +563,57 @@ public function testGetFieldDefinitionsWithCaching() { } /** + * Tests the getStorageFieldDefinitions() method with caching. + * + * @covers ::getStorageFieldDefinitions() + */ + public function testGetStorageFieldDefinitionsWithCaching() { + $field_definition = $this->setUpEntityWithFieldDefinition(TRUE, 'id', 0); + $storage_field_definition = $this->getMock('\Drupal\Core\Field\FieldStorageDefinitionInterface'); + $storage_field_definition->expects($this->any()) + ->method('getName') + ->will($this->returnValue('storage_field')); + + $this->moduleHandler->expects($this->any()) + ->method('getImplementations') + ->with('entity_storage_field_info') + ->will($this->returnValue(array('phpunit'))); + + $this->moduleHandler->expects($this->once()) + ->method('invoke') + ->with('phpunit') + ->will($this->returnValue(array('storage_field' => $storage_field_definition))); + + $expected = array( + 'id' => $field_definition, + 'storage_field' => $storage_field_definition, + ); + + $this->cache->expects($this->at(0)) + ->method('get') + ->with('entity_base_field_definitions:test_entity_type:en', FALSE) + ->will($this->returnValue((object) array('data' => array('id' => $expected['id'])))); + $this->cache->expects($this->at(1)) + ->method('get') + ->with('entity_storage_field_definitions:test_entity_type:en', FALSE) + ->will($this->returnValue(FALSE)); + $this->cache->expects($this->at(2)) + ->method('set'); + $this->cache->expects($this->at(3)) + ->method('get') + ->with('entity_base_field_definitions:test_entity_type:en', FALSE) + ->will($this->returnValue((object) array('data' => array('id' => $expected['id'])))); + $this->cache->expects($this->at(4)) + ->method('get') + ->with('entity_storage_field_definitions:test_entity_type:en', FALSE) + ->will($this->returnValue((object) array('data' => $expected))); + + $this->assertSame($expected, $this->entityManager->getStorageFieldDefinitions('test_entity_type')); + $this->entityManager->testClearEntityFieldInfo(); + $this->assertSame($expected, $this->entityManager->getStorageFieldDefinitions('test_entity_type')); + } + + /** * Tests the getBaseFieldDefinitions() method with an invalid definition. * * @covers ::getBaseFieldDefinitions() @@ -904,11 +981,12 @@ public function setDiscovery(DiscoveryInterface $discovery) { } /** - * Allows the $entityFieldInfo property to be cleared. + * Allows the static caches to be cleared. */ public function testClearEntityFieldInfo() { $this->baseFieldDefinitions = array(); $this->fieldDefinitions = array(); + $this->storageFieldDefinitions = array(); } } diff --git a/core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php b/core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php index 9637ccb..f901da2 100644 --- a/core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php @@ -116,7 +116,7 @@ public function testFieldDescription() { */ public function testFieldType() { $definition = FieldDefinition::create($this->fieldType); - $this->assertEquals($this->fieldType, $definition->getType()); + $this->assertEquals($this->fieldType, $definition->getTypeId()); } /**