diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index 654fc5e..60c120b 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -7,26 +7,12 @@ namespace Drupal\Core\Entity; -use Drupal\Core\TypedData\ComplexDataInterface; use Drupal\Core\TypedData\TranslatableInterface; /** * Defines a common interface for all content entity objects. - * - * This interface builds upon the general interfaces provided by the typed data - * API, while extending them with content entity-specific additions. I.e., a - * content entity implements the ComplexDataInterface among others, thus is - * complex data containing fields as its data properties. The contained fields - * have to implement \Drupal\Core\Field\FieldItemListInterface, - * which builds upon typed data interfaces as well. - * - * When implementing this interface which extends Traversable, make sure to list - * IteratorAggregate or Iterator before this interface in the implements clause. - * - * @see \Drupal\Core\TypedData\TypedDataManager - * @see \Drupal\Core\Field\FieldItemListInterface */ -interface ContentEntityInterface extends EntityInterface, RevisionableInterface, TranslatableInterface, ComplexDataInterface { +interface ContentEntityInterface extends FieldableEntityInterface, RevisionableInterface, TranslatableInterface { /** * Marks the translation identified by the given language code as existing. @@ -39,100 +25,4 @@ */ public function initTranslation($langcode); - /** - * Provides base field definitions for an entity type. - * - * Implementations typically use the class \Drupal\Core\Field\FieldDefinition - * for creating the field definitions; for example a 'name' field could be - * defined as the following: - * @code - * $fields['name'] = FieldDefinition::create('string') - * ->setLabel(t('Name')); - * @endcode - * - * If some elements in a field definition need to vary by bundle, use - * \Drupal\Core\Entity\ContentEntityInterface::bundleFieldDefinitions(). - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. Useful when a single class is used for multiple, - * possibly dynamic entity types. - * - * @return \Drupal\Core\Field\FieldDefinitionInterface[] - * An array of base field definitions for the entity type, keyed by field - * name. - * - * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() - * @see \Drupal\Core\Entity\ContentEntityInterface::bundleFieldDefinitions() - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type); - - /** - * Provides or alters field definitions for a specific bundle. - * - * The field definitions returned here for the bundle take precedence on the - * base field definitions specified by baseFieldDefinitions() for the entity - * type. - * - * @todo Provide a better DX for field overrides. - * See https://drupal.org/node/2145115. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. Useful when a single class is used for multiple, - * possibly dynamic entity types. - * @param string $bundle - * The bundle. - * @param \Drupal\Core\Field\FieldDefinitionInterface[] $base_field_definitions - * The list of base field definitions. - * - * @return \Drupal\Core\Field\FieldDefinitionInterface[] - * An array of bundle field definitions, keyed by field name. - * - * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() - * @see \Drupal\Core\Entity\ContentEntityInterface::baseFieldDefinitions() - */ - public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions); - - /** - * Returns whether the entity has a field with the given name. - * - * @param string $field_name - * The field name. - * - * @return bool - * TRUE if the entity has a field with the given name. FALSE otherwise. - */ - public function hasField($field_name); - - /** - * Gets the definition of a contained field. - * - * @param string $name - * The name of the field. - * - * @return \Drupal\Core\Field\FieldDefinitionInterface|null - * The definition of the field or null if the field does not exist. - */ - public function getFieldDefinition($name); - - /** - * Gets an array of field definitions of all contained fields. - * - * @return \Drupal\Core\Field\FieldDefinitionInterface[] - * An array of field definitions, keyed by field name. - * - * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() - */ - public function getFieldDefinitions(); - - /** - * Returns an array of all field values. - * - * Gets an array of plain field values, including only non-computed values. - * Note that the structure varies by entity type and bundle. - * - * @return array - * An array of field values, keyed by field name. - */ - public function toArray(); - } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 29c1de9..ef802b1 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -355,10 +355,10 @@ public function onFieldPurge(FieldConfigInterface $field) { } /** * Checks translation statuses and invoke the related hooks if needed. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity being saved. */ - protected function invokeTranslationHooks(ContentEntityInterface $entity) { + protected function invokeTranslationHooks(FieldableEntityInterface $entity) { $translations = $entity->getTranslationLanguages(FALSE); $original_translations = $entity->original->getTranslationLanguages(FALSE); $all_translations = array_keys($translations + $original_translations); @@ -379,10 +379,10 @@ protected function invokeTranslationHooks(ContentEntityInterface $entity) { * * @param string $method * The method name. - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity object. */ - protected function invokeFieldMethod($method, ContentEntityInterface $entity) { + protected function invokeFieldMethod($method, FieldableEntityInterface $entity) { foreach (array_keys($entity->getTranslationLanguages()) as $langcode) { $translation = $entity->getTranslation($langcode); foreach ($translation->getProperties(TRUE) as $field) { diff --git a/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php index 9db0a64..1ef08c9 100644 --- a/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php @@ -9,7 +9,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -70,7 +70,7 @@ public function view(EntityInterface $_entity, $view_mode = 'full', $langcode = // rendered title field formatter as the page title instead of the default // plain text title. This allows attributes set on the field to propagate // correctly (e.g. RDFa, in-place editing). - if ($_entity instanceof ContentEntityInterface) { + if ($_entity instanceof FieldableEntityInterface) { $label_field = $_entity->getEntityType()->getKey('label'); if ($label_field && $_entity->getFieldDefinition($label_field)->getDisplayOptions('view')) { // We must render the label field, because rendering the entity may be diff --git a/core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php b/core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php index 28a5aa3..b57b4cb 100644 --- a/core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php +++ b/core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Entity\Display; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; /** * Provides a common interface for entity form displays. @@ -91,7 +91,7 @@ * Additionally, some processing data is placed in $form_state, and can be * accessed by field_form_get_state() and field_form_set_state(). * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity. * @param array $form * The form structure to fill in. This can be a full form structure, or a @@ -103,7 +103,7 @@ * @param array $form_state * The form state. */ - public function buildForm(ContentEntityInterface $entity, array &$form, array &$form_state); + public function buildForm(FieldableEntityInterface $entity, array &$form, array &$form_state); /** * Validates submitted widget values and sets the corresponding form errors. @@ -124,7 +124,7 @@ public function buildForm(ContentEntityInterface $entity, array &$form, array &$ * It reports field constraint violations as form errors on the correct form * elements. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity. * @param array $form * The form structure where field elements are attached to. This might be a @@ -132,7 +132,7 @@ public function buildForm(ContentEntityInterface $entity, array &$form, array &$ * @param array $form_state * The form state. */ - public function validateFormValues(ContentEntityInterface $entity, array &$form, array &$form_state); + public function validateFormValues(FieldableEntityInterface $entity, array &$form, array &$form_state); /** * Extracts field values from the submitted widget values into the entity. @@ -140,7 +140,7 @@ public function validateFormValues(ContentEntityInterface $entity, array &$form, * This accounts for drag-and-drop reordering of field values, and filtering * of empty values. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity. * @param array $form * The form structure where field elements are attached to. This might be a @@ -154,6 +154,6 @@ public function validateFormValues(ContentEntityInterface $entity, array &$form, * any, do not correspond to widgets and should be extracted manually by * the caller if needed. */ - public function extractFormValues(ContentEntityInterface $entity, array &$form, array &$form_state); + public function extractFormValues(FieldableEntityInterface $entity, array &$form, array &$form_state); } diff --git a/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php b/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php index 69ecb78..3771d81 100644 --- a/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php +++ b/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Entity\Display; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; /** * Provides a common interface for entity view displays. @@ -19,7 +19,7 @@ * * See the buildMultiple() method for details. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity being displayed. * * @return array @@ -27,7 +27,7 @@ * * @see \Drupal\Core\Entity\Display\EntityViewDisplayInterface::buildMultiple() */ - public function build(ContentEntityInterface $entity); + public function build(FieldableEntityInterface $entity); /** * Returns a renderable array for the components of a set of entities. @@ -40,7 +40,7 @@ public function build(ContentEntityInterface $entity); * hook_entity_display_build_alter() is invoked on each entity, allowing 3rd * party code to alter the render array. * - * @param \Drupal\Core\Entity\ContentEntityInterface[] $entities + * @param \Drupal\Core\Entity\FieldableEntityInterface[] $entities * The entities being displayed. * * @return array diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 93e9fcf..2726b5b 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -340,7 +340,7 @@ public function getBaseFieldDefinitions($entity_type_id) { * * @param string $entity_type_id * The entity type ID. Only entity types that implement - * \Drupal\Core\Entity\ContentEntityInterface are supported. + * \Drupal\Core\Entity\FieldableEntityInterface are supported. * * @return \Drupal\Core\Field\FieldDefinitionInterface[] * An array of field definitions, keyed by field name. @@ -354,7 +354,7 @@ protected function buildBaseFieldDefinitions($entity_type_id) { $class = $entity_type->getClass(); // Fail with an exception for config entity types. - if (!$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + if (!$entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { throw new \LogicException(String::format('Getting the base fields is not supported for entity type @type.', array('@type' => $entity_type->getLabel()))); } @@ -441,7 +441,7 @@ public function getFieldDefinitions($entity_type_id, $bundle) { * * @param string $entity_type_id * The entity type ID. Only entity types that implement - * \Drupal\Core\Entity\ContentEntityInterface are supported. + * \Drupal\Core\Entity\FieldableEntityInterface are supported. * @param string $bundle * The bundle. * @param \Drupal\Core\Field\FieldDefinitionInterface[] $base_field_definitions @@ -537,7 +537,7 @@ public function getFieldMap() { else { // Rebuild the definitions and put it into the cache. foreach ($this->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + if ($entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { foreach ($this->getBundleInfo($entity_type_id) as $bundle => $bundle_info) { foreach ($this->getFieldDefinitions($entity_type_id, $bundle) as $field_name => $field_definition) { $this->fieldMap[$entity_type_id][$field_name]['type'] = $field_definition->getType(); @@ -558,7 +558,7 @@ public function getFieldMap() { * * @param string $entity_type_id * The entity type ID. Only entity types that implement - * \Drupal\Core\Entity\ContentEntityInterface are supported + * \Drupal\Core\Entity\FieldableEntityInterface are supported * * @return \Drupal\Core\Field\FieldStorageDefinitionInterface[] * An array of field storage definitions, keyed by field name. diff --git a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php index 104f774..dc6cb87 100644 --- a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php @@ -35,7 +35,7 @@ public function getEntityTypeLabels($group = FALSE); * * @param string $entity_type_id * The entity type ID. Only entity types that implement - * \Drupal\Core\Entity\ContentEntityInterface are supported. + * \Drupal\Core\Entity\FieldableEntityInterface are supported. * * @return \Drupal\Core\Field\FieldDefinitionInterface[] * The array of base field definitions for the entity type, keyed by field @@ -51,7 +51,7 @@ public function getBaseFieldDefinitions($entity_type_id); * * @param string $entity_type_id * The entity type ID. Only entity types that implement - * \Drupal\Core\Entity\ContentEntityInterface are supported. + * \Drupal\Core\Entity\FieldableEntityInterface are supported. * @param string $bundle * The bundle. * diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 2942038..d355b39 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Language\Language; @@ -247,7 +247,7 @@ public function buildMultiple(array $build_list) { foreach ($children as $key) { if (isset($build_list[$key][$entity_type_key])) { $entity = $build_list[$key][$entity_type_key]; - if ($entity instanceof ContentEntityInterface) { + if ($entity instanceof FieldableEntityInterface) { $view_modes[$build_list[$key]['#view_mode']][$key] = $entity; } } diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php new file mode 100644 index 0000000..e3c814f --- /dev/null +++ b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php @@ -0,0 +1,125 @@ +setLabel(t('Name')); + * @endcode + * + * If some elements in a field definition need to vary by bundle, use + * \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions(). + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. Useful when a single class is used for multiple, + * possibly dynamic entity types. + * + * @return \Drupal\Core\Field\FieldDefinitionInterface[] + * An array of base field definitions for the entity type, keyed by field + * name. + * + * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() + * @see \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions() + */ + public static function baseFieldDefinitions(EntityTypeInterface $entity_type); + + /** + * Provides or alters field definitions for a specific bundle. + * + * The field definitions returned here for the bundle take precedence on the + * base field definitions specified by baseFieldDefinitions() for the entity + * type. + * + * @todo Provide a better DX for field overrides. + * See https://drupal.org/node/2145115. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. Useful when a single class is used for multiple, + * possibly dynamic entity types. + * @param string $bundle + * The bundle. + * @param \Drupal\Core\Field\FieldDefinitionInterface[] $base_field_definitions + * The list of base field definitions. + * + * @return \Drupal\Core\Field\FieldDefinitionInterface[] + * An array of bundle field definitions, keyed by field name. + * + * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() + * @see \Drupal\Core\Entity\FieldableEntityInterface::baseFieldDefinitions() + */ + public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions); + + /** + * Returns whether the entity has a field with the given name. + * + * @param string $field_name + * The field name. + * + * @return bool + * TRUE if the entity has a field with the given name. FALSE otherwise. + */ + public function hasField($field_name); + + /** + * Gets the definition of a contained field. + * + * @param string $name + * The name of the field. + * + * @return \Drupal\Core\Field\FieldDefinitionInterface|null + * The definition of the field or null if the field does not exist. + */ + public function getFieldDefinition($name); + + /** + * Gets an array of field definitions of all contained fields. + * + * @return \Drupal\Core\Field\FieldDefinitionInterface[] + * An array of field definitions, keyed by field name. + * + * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() + */ + public function getFieldDefinitions(); + + /** + * Returns an array of all field values. + * + * Gets an array of plain field values, including only non-computed values. + * Note that the structure varies by entity type and bundle. + * + * @return array + * An array of field values, keyed by field name. + */ + public function toArray(); +} diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php index 442162c..3d34f76 100644 --- a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityStorageBase; @@ -98,10 +98,10 @@ public function doCreate(array $values = array()) { $entity = new $this->entityClass($values, $this->entityTypeId); // @todo This is handled by ContentEntityStorageBase, which assumes - // ContentEntityInterface. The current approach in + // FieldableEntityInterface. The current approach in // https://drupal.org/node/1867228 improves this but does not solve it // completely. - if ($entity instanceof ContentEntityInterface) { + if ($entity instanceof FieldableEntityInterface) { foreach ($entity as $name => $field) { if (isset($values[$name])) { $entity->$name = $values[$name]; 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 7a02254..379ab92 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -59,7 +59,7 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel $settings = $field_definition->getSettings(); $target_type_info = \Drupal::entityManager()->getDefinition($settings['target_type']); - if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { // @todo: Lookup the entity type's ID data type and use it here. // https://drupal.org/node/2107249 $target_id_definition = DataDefinition::create('integer') diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 1834e55..2957ea2 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -13,7 +13,7 @@ use Drupal\comment\CommentInterface; use Drupal\comment\Entity\Comment; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; @@ -313,7 +313,7 @@ function comment_permission() { * Number of comments. * @param int $new_replies * Number of new replies. - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The first new comment entity. * @param string $field_name * The field name on the entity to which comments are attached to. @@ -321,7 +321,7 @@ function comment_permission() { * @return array|null * An array "page=X" if the page number is greater than zero; NULL otherwise. */ -function comment_new_page_count($num_comments, $new_replies, ContentEntityInterface $entity, $field_name = 'comment') { +function comment_new_page_count($num_comments, $new_replies, FieldableEntityInterface $entity, $field_name = 'comment') { $field_definition = $entity->getFieldDefinition($field_name); $mode = $field_definition->getSetting('default_mode'); $comments_per_page = $field_definition->getSetting('per_page'); @@ -875,7 +875,7 @@ function comment_translation_configuration_element_submit($form, &$form_state) { */ function comment_entity_load($entities, $entity_type) { // Comments can only be attached to content entities, so skip others. - if (!\Drupal::entityManager()->getDefinition($entity_type)->isSubclassOf('Drupal\Core\Entity\ContentEntityInterface')) { + if (!\Drupal::entityManager()->getDefinition($entity_type)->isSubclassOf('Drupal\Core\Entity\FieldableEntityInterface')) { return; } if (!\Drupal::service('comment.manager')->getFields($entity_type)) { diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index 058bdc5..7b7cad3 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -246,7 +246,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = } elseif (($type == 'entity' & !empty($data['entity'])) || ($type == 'node' & !empty($data['node']))) { - /** @var $entity \Drupal\Core\Entity\ContentEntityInterface */ + /** @var $entity \Drupal\Core\Entity\FieldableEntityInterface */ $entity = !empty($data['entity']) ? $data['entity'] : $data['node']; foreach ($tokens as $name => $original) { diff --git a/core/modules/comment/src/CommentInterface.php b/core/modules/comment/src/CommentInterface.php index 48af294..112086a 100644 --- a/core/modules/comment/src/CommentInterface.php +++ b/core/modules/comment/src/CommentInterface.php @@ -7,6 +7,7 @@ namespace Drupal\comment; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\user\EntityOwnerInterface; use Drupal\Core\Entity\EntityChangedInterface; diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php index 7bd9f0f..c41c197 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -75,7 +75,7 @@ public function __construct(EntityManagerInterface $entity_manager, ConfigFactor */ public function getFields($entity_type_id) { $entity_type = $this->entityManager->getDefinition($entity_type_id); - if (!$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + if (!$entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { return array(); } diff --git a/core/modules/comment/src/CommentStatistics.php b/core/modules/comment/src/CommentStatistics.php index 9e3fbd1..23f4080 100644 --- a/core/modules/comment/src/CommentStatistics.php +++ b/core/modules/comment/src/CommentStatistics.php @@ -8,7 +8,7 @@ use Drupal\Core\Database\Connection; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; @@ -90,7 +90,7 @@ public function delete(EntityInterface $entity) { /** * {@inheritdoc} */ - public function create(ContentEntityInterface $entity, $fields) { + public function create(FieldableEntityInterface $entity, $fields) { $query = $this->database->insert('comment_entity_statistics') ->fields(array( 'entity_id', diff --git a/core/modules/comment/src/CommentStatisticsInterface.php b/core/modules/comment/src/CommentStatisticsInterface.php index dc34e96..4a2e17f 100644 --- a/core/modules/comment/src/CommentStatisticsInterface.php +++ b/core/modules/comment/src/CommentStatisticsInterface.php @@ -6,7 +6,7 @@ namespace Drupal\comment; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityInterface; /** @@ -72,11 +72,11 @@ public function getMaximumCount($entity_type); /** * Insert an empty record for the given entity. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The created entity for which a statistics record is to be initialized. * @param array $fields * Array of comment field definitions for the given entity. */ - public function create(ContentEntityInterface $entity, $fields); + public function create(FieldableEntityInterface $entity, $fields); } diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 9da1540..1807de9 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -6,7 +6,7 @@ */ use Drupal\Component\Utility\Html; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Render\Element; use Drupal\editor\Entity\Editor; use Drupal\Component\Utility\NestedArray; @@ -404,7 +404,7 @@ function editor_filter_xss($html, FilterFormatInterface $format, FilterFormatInt */ function editor_entity_insert(EntityInterface $entity) { // Only act on content entities. - if (!($entity instanceof ContentEntityInterface)) { + if (!($entity instanceof FieldableEntityInterface)) { return; } $referenced_files_by_field = _editor_get_file_uuids_by_field($entity); @@ -418,7 +418,7 @@ function editor_entity_insert(EntityInterface $entity) { */ function editor_entity_update(EntityInterface $entity) { // Only act on content entities. - if (!($entity instanceof ContentEntityInterface)) { + if (!($entity instanceof FieldableEntityInterface)) { return; } @@ -457,7 +457,7 @@ function editor_entity_update(EntityInterface $entity) { */ function editor_entity_delete(EntityInterface $entity) { // Only act on content entities. - if (!($entity instanceof ContentEntityInterface)) { + if (!($entity instanceof FieldableEntityInterface)) { return; } $referenced_files_by_field = _editor_get_file_uuids_by_field($entity); @@ -471,7 +471,7 @@ function editor_entity_delete(EntityInterface $entity) { */ function editor_entity_revision_delete(EntityInterface $entity) { // Only act on content entities. - if (!($entity instanceof ContentEntityInterface)) { + if (!($entity instanceof FieldableEntityInterface)) { return; } $referenced_files_by_field = _editor_get_file_uuids_by_field($entity); @@ -551,7 +551,7 @@ function _editor_get_file_uuids_by_field(EntityInterface $entity) { * @return array * The names of the fields on this entity that have text processing enabled. */ -function _editor_get_processed_text_fields(ContentEntityInterface $entity) { +function _editor_get_processed_text_fields(FieldableEntityInterface $entity) { $field_definitions = $entity->getFieldDefinitions(); if (empty($field_definitions)) { return array(); diff --git a/core/modules/entity/src/Entity/EntityFormDisplay.php b/core/modules/entity/src/Entity/EntityFormDisplay.php index 8365032..dc8f45a 100644 --- a/core/modules/entity/src/Entity/EntityFormDisplay.php +++ b/core/modules/entity/src/Entity/EntityFormDisplay.php @@ -7,7 +7,7 @@ namespace Drupal\entity\Entity; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\entity\EntityDisplayBase; @@ -50,7 +50,7 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn * party code to alter the display options held in the display before they are * used to generate render arrays. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity for which the form is being built. * @param string $form_mode * The form mode. @@ -61,7 +61,7 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn * @see entity_get_form_display() * @see hook_entity_form_display_alter() */ - public static function collectRenderDisplay(ContentEntityInterface $entity, $form_mode) { + public static function collectRenderDisplay(FieldableEntityInterface $entity, $form_mode) { $entity_type = $entity->getEntityTypeId(); $bundle = $entity->bundle(); @@ -148,7 +148,7 @@ public function getRenderer($field_name) { /** * {@inheritdoc} */ - public function buildForm(ContentEntityInterface $entity, array &$form, array &$form_state) { + public function buildForm(FieldableEntityInterface $entity, array &$form, array &$form_state) { // Set #parents to 'top-level' by default. $form += array('#parents' => array()); @@ -197,7 +197,7 @@ public function processForm($element, $form_state, $form) { /** * {@inheritdoc} */ - public function extractFormValues(ContentEntityInterface $entity, array &$form, array &$form_state) { + public function extractFormValues(FieldableEntityInterface $entity, array &$form, array &$form_state) { $extracted = array(); foreach ($entity as $name => $items) { if ($widget = $this->getRenderer($name)) { @@ -211,7 +211,7 @@ public function extractFormValues(ContentEntityInterface $entity, array &$form, /** * {@inheritdoc} */ - public function validateFormValues(ContentEntityInterface $entity, array &$form, array &$form_state) { + public function validateFormValues(FieldableEntityInterface $entity, array &$form, array &$form_state) { foreach ($entity as $field_name => $items) { // Only validate the fields that actually appear in the form, and let the // widget assign the violations to the right form elements. diff --git a/core/modules/entity/src/Entity/EntityViewDisplay.php b/core/modules/entity/src/Entity/EntityViewDisplay.php index 3dcc55d..a34e9aa 100644 --- a/core/modules/entity/src/Entity/EntityViewDisplay.php +++ b/core/modules/entity/src/Entity/EntityViewDisplay.php @@ -9,7 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\entity\EntityDisplayBase; /** @@ -54,7 +54,7 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn * party code to alter the display options held in the display before they are * used to generate render arrays. * - * @param \Drupal\Core\Entity\ContentEntityInterface[] $entities + * @param \Drupal\Core\Entity\FieldableEntityInterface[] $entities * The entities being rendered. They should all be of the same entity type. * @param string $view_mode * The view mode being rendered. @@ -146,7 +146,7 @@ public static function collectRenderDisplays($entities, $view_mode) { * * See the collectRenderDisplays() method for details. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity being rendered. * @param string $view_mode * The view mode. @@ -156,7 +156,7 @@ public static function collectRenderDisplays($entities, $view_mode) { * * @see \Drupal\entity\Entity\EntityDisplay::collectRenderDisplays() */ - public static function collectRenderDisplay(ContentEntityInterface $entity, $view_mode) { + public static function collectRenderDisplay(FieldableEntityInterface $entity, $view_mode) { $displays = static::collectRenderDisplays(array($entity), $view_mode); return $displays[$entity->bundle()]; } @@ -200,7 +200,7 @@ public function getRenderer($field_name) { /** * {@inheritdoc} */ - public function build(ContentEntityInterface $entity) { + public function build(FieldableEntityInterface $entity) { $build = $this->buildMultiple(array($entity)); return $build[0]; } diff --git a/core/modules/entity/src/EntityDisplayBase.php b/core/modules/entity/src/EntityDisplayBase.php index 34dc815..5979e2f 100644 --- a/core/modules/entity/src/EntityDisplayBase.php +++ b/core/modules/entity/src/EntityDisplayBase.php @@ -112,7 +112,7 @@ public function __construct(array $values, $entity_type) { throw new \InvalidArgumentException('Missing required properties for an EntityDisplay entity.'); } - if (!$this->entityManager()->getDefinition($values['targetEntityType'])->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + if (!$this->entityManager()->getDefinition($values['targetEntityType'])->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { throw new \InvalidArgumentException('EntityDisplay entities can only handle content entity types.'); } @@ -364,7 +364,7 @@ protected function getFieldDefinition($field_name) { protected function getFieldDefinitions() { // Entity displays are sometimes created for non-content entities. // @todo Prevent this in https://drupal.org/node/2095195. - if (!\Drupal::entityManager()->getDefinition($this->targetEntityType)->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + if (!\Drupal::entityManager()->getDefinition($this->targetEntityType)->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { return array(); } diff --git a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php index e5ad209..d25a02d 100644 --- a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php @@ -144,7 +144,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) $target_type = $field_definition->getSetting('target_type'); $target_type_info = \Drupal::entityManager()->getDefinition($target_type); - if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') && $field_definition instanceof FieldConfigInterface) { + if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface') && $field_definition instanceof FieldConfigInterface) { $schema['columns']['revision_id'] = array( 'description' => 'The revision ID of the target entity.', 'type' => 'int', diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidgetBase.php b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidgetBase.php index 2ed1dfe..28cd4d4 100644 --- a/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidgetBase.php +++ b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidgetBase.php @@ -218,7 +218,7 @@ protected function getSelectionHandlerSetting($setting_name) { protected function isContentReferenced() { $target_type = $this->getFieldSetting('target_type'); $target_type_info = \Drupal::entityManager()->getDefinition($target_type); - return $target_type_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface'); + return $target_type_info->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface'); } } diff --git a/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php b/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php index 650486c..c0ef751 100644 --- a/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php +++ b/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php @@ -100,7 +100,7 @@ public static function settingsForm(FieldDefinitionInterface $field_definition) ); } - if ($entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + if ($entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { $fields = array(); foreach (array_keys($bundles) as $bundle) { $bundle_fields = array_filter($entity_manager->getFieldDefinitions($entity_type_id, $bundle), function ($field_definition) { diff --git a/core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php b/core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php index d5ba85a..44ba171 100644 --- a/core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php +++ b/core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php @@ -7,7 +7,7 @@ namespace Drupal\hal\Normalizer; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\rest\LinkManager\LinkManagerInterface; use Drupal\serialization\EntityResolver\EntityResolverInterface; use Drupal\serialization\EntityResolver\UuidReferenceInterface; @@ -60,7 +60,7 @@ public function normalize($field_item, $format = NULL, array $context = array()) // If this is not a content entity, let the parent implementation handle it, // only content entities are supported as embedded resources. - if (!($target_entity instanceof ContentEntityInterface)) { + if (!($target_entity instanceof FieldableEntityInterface)) { return parent::normalize($field_item, $format, $context); } diff --git a/core/modules/path/path.module b/core/modules/path/path.module index 1e089ac..0267e7d 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -8,7 +8,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Language\Language; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Field\FieldDefinition; use Symfony\Component\HttpFoundation\Request; diff --git a/core/modules/quickedit/src/Form/QuickEditFieldForm.php b/core/modules/quickedit/src/Form/QuickEditFieldForm.php index ae22614..e105927 100644 --- a/core/modules/quickedit/src/Form/QuickEditFieldForm.php +++ b/core/modules/quickedit/src/Form/QuickEditFieldForm.php @@ -7,7 +7,7 @@ namespace Drupal\quickedit\Form; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityChangedInterface; @@ -237,13 +237,13 @@ protected function simplify(array &$form, array &$form_state) { /** * Finds the field name for the field carrying the changed timestamp, if any. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity. * * @return string|null * The name of the field found or NULL if not found. */ - protected function getChangedFieldName(ContentEntityInterface $entity) { + protected function getChangedFieldName(FieldableEntityInterface $entity) { foreach ($entity->getFieldDefinitions() as $field) { if ($field->getType() == 'changed') { return $field->getName(); diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 50b9f6a..2f112ba 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -6,7 +6,7 @@ */ use Drupal\Component\Utility\String; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Field\FieldDefinition; use Drupal\Core\Render\Element; @@ -258,7 +258,7 @@ function hook_entity_bundle_delete($entity_type_id, $bundle) { * The entity object. */ function hook_entity_create(\Drupal\Core\Entity\EntityInterface $entity) { - if ($entity instanceof ContentEntityInterface && !$entity->foo->value) { + if ($entity instanceof FieldableEntityInterface && !$entity->foo->value) { $entity->foo->value = 'some_initial_value'; } } diff --git a/core/modules/system/src/Tests/Entity/FieldTranslationSqlStorageTest.php b/core/modules/system/src/Tests/Entity/FieldTranslationSqlStorageTest.php index b9d8cec..deff458 100644 --- a/core/modules/system/src/Tests/Entity/FieldTranslationSqlStorageTest.php +++ b/core/modules/system/src/Tests/Entity/FieldTranslationSqlStorageTest.php @@ -7,7 +7,7 @@ namespace Drupal\system\Tests\Entity; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\ContentEntityDatabaseStorage; use Drupal\Core\Language\Language; use Drupal\field\Entity\FieldConfig; @@ -78,12 +78,12 @@ public function testFieldSqlStorage() { /** * Checks whether field languages are correctly stored for the given entity. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity fields are attached to. * @param string $message * (optional) A message to display with the assertion. */ - protected function assertFieldStorageLangcode(ContentEntityInterface $entity, $message = '') { + protected function assertFieldStorageLangcode(FieldableEntityInterface $entity, $message = '') { $status = TRUE; $entity_type = $entity->getEntityTypeId(); $id = $entity->id(); diff --git a/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php b/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php index 3357d1d..9bda703 100644 --- a/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php +++ b/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php @@ -7,7 +7,7 @@ namespace Drupal\text\Tests\Formatter; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Language\Language; use Drupal\simpletest\DrupalUnitTestBase; @@ -116,12 +116,12 @@ protected function createEntity($values = array()) { /** * Renders fields of a given entity with a given display. * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity object with attached fields to render. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display * The display to render the fields in. */ - protected function renderEntityFields(ContentEntityInterface $entity, EntityViewDisplayInterface $display) { + protected function renderEntityFields(FieldableEntityInterface $entity, EntityViewDisplayInterface $display) { $content = $display->build($entity); $this->content = drupal_render($content); return $this->content; diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index e5eeda0..e88332a 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -751,7 +751,7 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f ->will($this->returnValue(array())); $entity_type->expects($this->any()) ->method('isSubclassOf') - ->with($this->equalTo('\Drupal\Core\Entity\ContentEntityInterface')) + ->with($this->equalTo('\Drupal\Core\Entity\FieldableEntityInterface')) ->will($this->returnValue(TRUE)); $field_definition = $this->getMockBuilder('Drupal\Core\Field\FieldDefinition') ->disableOriginalConstructor() @@ -1062,7 +1062,7 @@ public function testGetFieldMap() { ->will($this->returnValue(array())); $entity_type->expects($this->any()) ->method('isSubclassOf') - ->with('\Drupal\Core\Entity\ContentEntityInterface') + ->with('\Drupal\Core\Entity\FieldableEntityInterface') ->will($this->returnValue(TRUE)); // Set up the module handler to return two bundles for the fieldable entity @@ -1133,7 +1133,7 @@ public function testGetFieldMap() { $non_content_entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); $entity_type->expects($this->any()) ->method('isSubclassOf') - ->with('\Drupal\Core\Entity\ContentEntityInterface') + ->with('\Drupal\Core\Entity\FieldableEntityInterface') ->will($this->returnValue(FALSE)); $this->setUpEntityManager(array(