Issue #2275659 by fago, pgautam: Separate FieldableEntityInterface out of ContentEntityInterface.
parent
51a6720f04
commit
ba2b869092
|
@ -12,22 +12,20 @@ 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.
|
||||
* Content entities use fields for all their entity properties and are
|
||||
* translatable and revisionable, while translations and revisions can be
|
||||
* enabled per entity type. It's best practice to always implement
|
||||
* ContentEntityInterface for content-like entities that should be stored in
|
||||
* some database, and enable/disable revisions and translations as desired.
|
||||
*
|
||||
* 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
|
||||
* @see \Drupal\Core\Entity\ContentEntityBase
|
||||
*
|
||||
* @ingroup entity_api
|
||||
*/
|
||||
interface ContentEntityInterface extends \Traversable, EntityInterface, RevisionableInterface, TranslatableInterface {
|
||||
interface ContentEntityInterface extends \Traversable, FieldableEntityInterface, RevisionableInterface, TranslatableInterface {
|
||||
|
||||
/**
|
||||
* Marks the translation identified by the given language code as existing.
|
||||
|
@ -40,181 +38,4 @@ interface ContentEntityInterface extends \Traversable, EntityInterface, Revision
|
|||
*/
|
||||
public function initTranslation($langcode);
|
||||
|
||||
/**
|
||||
* Provides base field definitions for an entity type.
|
||||
*
|
||||
* Implementations typically use the class
|
||||
* \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions;
|
||||
* for example a 'name' field could be defined as the following:
|
||||
* @code
|
||||
* $fields['name'] = BaseFieldDefinition::create('string')
|
||||
* ->setLabel(t('Name'));
|
||||
* @endcode
|
||||
*
|
||||
* By definition, base fields are fields that exist for every bundle. To
|
||||
* provide definitions for fields that should only exist on some bundles, use
|
||||
* \Drupal\Core\Entity\ContentEntityInterface::bundleFieldDefinitions().
|
||||
*
|
||||
* The definitions returned by this function can be overridden for all
|
||||
* bundles by hook_entity_base_field_info_alter() or overridden on a
|
||||
* per-bundle basis via 'base_field_override' configuration entities.
|
||||
*
|
||||
* @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 field definitions for a specific bundle.
|
||||
*
|
||||
* This function can return definitions both for bundle fields (fields that
|
||||
* are not defined in $base_field_definitions, and therefore might not exist
|
||||
* on some bundles) as well as bundle-specific overrides of base fields
|
||||
* (fields that are defined in $base_field_definitions, and therefore exist
|
||||
* for all bundles). However, bundle-specific base field overrides can also
|
||||
* be provided by 'base_field_override' configuration entities, and that is
|
||||
* the recommended approach except in cases where an entity type needs to
|
||||
* provide a bundle-specific base field override that is decoupled from
|
||||
* configuration. Note that for most entity types, the bundles themselves are
|
||||
* derived from configuration (e.g., 'node' bundles are managed via
|
||||
* 'node_type' configuration entities), so decoupling bundle-specific base
|
||||
* field overrides from configuration only makes sense for entity types that
|
||||
* also decouple their bundles from configuration. In cases where both this
|
||||
* function returns a bundle-specific override of a base field and a
|
||||
* 'base_field_override' configuration entity exists, the latter takes
|
||||
* precedence.
|
||||
*
|
||||
* @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()
|
||||
*
|
||||
* @todo WARNING: This method will be changed in
|
||||
* https://www.drupal.org/node/2346347.
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* Gets a field item list.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the field to get; e.g., 'title' or 'name'.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If an invalid field name is given.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldItemListInterface
|
||||
* The field item list, containing the field items.
|
||||
*/
|
||||
public function get($field_name);
|
||||
|
||||
/**
|
||||
* Sets a field value.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the field to set; e.g., 'title' or 'name'.
|
||||
* @param mixed $value
|
||||
* The value to set, or NULL to unset the field.
|
||||
* @param bool $notify
|
||||
* (optional) Whether to notify the entity of the change. Defaults to
|
||||
* TRUE. If the update stems from the entity, set it to FALSE to avoid
|
||||
* being notified again.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If the specified field does not exist.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set($field_name, $value, $notify = TRUE);
|
||||
|
||||
/**
|
||||
* Gets an array of field item lists.
|
||||
*
|
||||
* @param bool $include_computed
|
||||
* If set to TRUE, computed fields are included. Defaults to FALSE.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldItemListInterface[]
|
||||
* An array of field item lists implementing, keyed by field name.
|
||||
*/
|
||||
public function getFields($include_computed = TRUE);
|
||||
|
||||
/**
|
||||
* Reacts to changes to a field.
|
||||
*
|
||||
* Note that this is invoked after any changes have been applied.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the field which is changed.
|
||||
*/
|
||||
public function onChange($field_name);
|
||||
|
||||
/**
|
||||
* Validates the currently set values.
|
||||
*
|
||||
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
|
||||
* A list of constraint violations. If the list is empty, validation
|
||||
* succeeded.
|
||||
*/
|
||||
public function validate();
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Drupal\Core\Entity\Controller;
|
|||
|
||||
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 @@ class EntityViewController implements ContainerInjectionInterface {
|
|||
// 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
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Entity\Display;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
|
@ -86,7 +86,7 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface {
|
|||
* accessed by \Drupal\Core\Field\WidgetBaseInterface::getWidgetState() and
|
||||
* \Drupal\Core\Field\WidgetBaseInterface::setWidgetState().
|
||||
*
|
||||
* @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
|
||||
|
@ -98,7 +98,7 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface {
|
|||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The form state.
|
||||
*/
|
||||
public function buildForm(ContentEntityInterface $entity, array &$form, FormStateInterface $form_state);
|
||||
public function buildForm(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state);
|
||||
|
||||
/**
|
||||
* Validates submitted widget values and sets the corresponding form errors.
|
||||
|
@ -119,7 +119,7 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface {
|
|||
* 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
|
||||
|
@ -127,7 +127,7 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface {
|
|||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The form state.
|
||||
*/
|
||||
public function validateFormValues(ContentEntityInterface $entity, array &$form, FormStateInterface $form_state);
|
||||
public function validateFormValues(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state);
|
||||
|
||||
/**
|
||||
* Extracts field values from the submitted widget values into the entity.
|
||||
|
@ -135,7 +135,7 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface {
|
|||
* 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
|
||||
|
@ -149,6 +149,6 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface {
|
|||
* if any, do not correspond to widgets and should be extracted manually by
|
||||
* the caller if needed.
|
||||
*/
|
||||
public function extractFormValues(ContentEntityInterface $entity, array &$form, FormStateInterface $form_state);
|
||||
public function extractFormValues(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state);
|
||||
|
||||
}
|
||||
|
|
|
@ -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 @@ interface EntityViewDisplayInterface extends EntityDisplayInterface {
|
|||
*
|
||||
* 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 @@ interface EntityViewDisplayInterface extends EntityDisplayInterface {
|
|||
*
|
||||
* @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 @@ interface EntityViewDisplayInterface extends EntityDisplayInterface {
|
|||
* 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
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Entity\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
|
||||
use Drupal\Core\Entity\EntityDisplayBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
@ -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 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(ContentEntityInterface $entity, array &$form, FormStateInterface $form_state) {
|
||||
public function buildForm(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state) {
|
||||
// Set #parents to 'top-level' by default.
|
||||
$form += array('#parents' => array());
|
||||
|
||||
|
@ -197,7 +197,7 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function extractFormValues(ContentEntityInterface $entity, array &$form, FormStateInterface $form_state) {
|
||||
public function extractFormValues(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state) {
|
||||
$extracted = array();
|
||||
foreach ($entity as $name => $items) {
|
||||
if ($widget = $this->getRenderer($name)) {
|
||||
|
@ -211,7 +211,7 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateFormValues(ContentEntityInterface $entity, array &$form, FormStateInterface $form_state) {
|
||||
public function validateFormValues(FieldableEntityInterface $entity, array &$form, FormStateInterface $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.
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Drupal\Core\Entity\Entity;
|
|||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\EntityDisplayBase;
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,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.
|
||||
|
@ -142,7 +142,7 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn
|
|||
*
|
||||
* 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.
|
||||
|
@ -152,7 +152,7 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn
|
|||
*
|
||||
* @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()];
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(ContentEntityInterface $entity) {
|
||||
public function build(FieldableEntityInterface $entity) {
|
||||
$build = $this->buildMultiple(array($entity));
|
||||
return $build[0];
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
|
|||
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.');
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ use Drupal\Core\Access\AccessibleInterface;
|
|||
|
||||
/**
|
||||
* Defines a common interface for all entity objects.
|
||||
*
|
||||
* @ingroup entity_api
|
||||
*/
|
||||
interface EntityInterface extends AccessibleInterface {
|
||||
|
||||
|
|
|
@ -353,7 +353,7 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
|
|||
*
|
||||
* @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.
|
||||
|
@ -366,8 +366,8 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
|
|||
$entity_type = $this->getDefinition($entity_type_id);
|
||||
$class = $entity_type->getClass();
|
||||
|
||||
// Fail with an exception for config entity types.
|
||||
if (!$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) {
|
||||
// Fail with an exception for non-fieldable entity types.
|
||||
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())));
|
||||
}
|
||||
|
||||
|
@ -456,7 +456,7 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
|
|||
*
|
||||
* @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
|
||||
|
@ -568,7 +568,7 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
|
|||
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();
|
||||
|
@ -608,7 +608,7 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
|
|||
*
|
||||
* @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.
|
||||
|
@ -987,7 +987,7 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
|
|||
}
|
||||
|
||||
$this->setLastInstalledDefinition($entity_type);
|
||||
if ($entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) {
|
||||
if ($entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) {
|
||||
$this->setLastInstalledFieldStorageDefinitions($entity_type_id, $this->getFieldStorageDefinitions($entity_type_id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ interface EntityManagerInterface extends PluginManagerInterface, EntityTypeListe
|
|||
*
|
||||
* @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
|
||||
|
@ -52,7 +52,7 @@ interface EntityManagerInterface extends PluginManagerInterface, EntityTypeListe
|
|||
*
|
||||
* @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.
|
||||
*
|
||||
|
|
|
@ -247,7 +247,7 @@ class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterf
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\FieldableEntityInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\TypedData\ComplexDataInterface;
|
||||
|
||||
/**
|
||||
* Interface for entities having fields.
|
||||
*
|
||||
* This interface builds upon the general interfaces provided by the typed data
|
||||
* API, while extending them with entity-specific additions. I.e., fieldable
|
||||
* entities implement the ComplexDataInterface among others, thus it 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
|
||||
*
|
||||
* @ingroup entity_api
|
||||
*/
|
||||
interface FieldableEntityInterface extends EntityInterface {
|
||||
|
||||
/**
|
||||
* Provides base field definitions for an entity type.
|
||||
*
|
||||
* Implementations typically use the class
|
||||
* \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions;
|
||||
* for example a 'name' field could be defined as the following:
|
||||
* @code
|
||||
* $fields['name'] = BaseFieldDefinition::create('string')
|
||||
* ->setLabel(t('Name'));
|
||||
* @endcode
|
||||
*
|
||||
* By definition, base fields are fields that exist for every bundle. To
|
||||
* provide definitions for fields that should only exist on some bundles, use
|
||||
* \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().
|
||||
*
|
||||
* The definitions returned by this function can be overridden for all
|
||||
* bundles by hook_entity_base_field_info_alter() or overridden on a
|
||||
* per-bundle basis via 'base_field_override' configuration entities.
|
||||
*
|
||||
* @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 field definitions for a specific bundle.
|
||||
*
|
||||
* This function can return definitions both for bundle fields (fields that
|
||||
* are not defined in $base_field_definitions, and therefore might not exist
|
||||
* on some bundles) as well as bundle-specific overrides of base fields
|
||||
* (fields that are defined in $base_field_definitions, and therefore exist
|
||||
* for all bundles). However, bundle-specific base field overrides can also
|
||||
* be provided by 'base_field_override' configuration entities, and that is
|
||||
* the recommended approach except in cases where an entity type needs to
|
||||
* provide a bundle-specific base field override that is decoupled from
|
||||
* configuration. Note that for most entity types, the bundles themselves are
|
||||
* derived from configuration (e.g., 'node' bundles are managed via
|
||||
* 'node_type' configuration entities), so decoupling bundle-specific base
|
||||
* field overrides from configuration only makes sense for entity types that
|
||||
* also decouple their bundles from configuration. In cases where both this
|
||||
* function returns a bundle-specific override of a base field and a
|
||||
* 'base_field_override' configuration entity exists, the latter takes
|
||||
* precedence.
|
||||
*
|
||||
* @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()
|
||||
*
|
||||
* @todo WARNING: This method will be changed in
|
||||
* https://www.drupal.org/node/2346347.
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* Gets a field item list.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the field to get; e.g., 'title' or 'name'.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If an invalid field name is given.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldItemListInterface
|
||||
* The field item list, containing the field items.
|
||||
*/
|
||||
public function get($field_name);
|
||||
|
||||
/**
|
||||
* Sets a field value.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the field to set; e.g., 'title' or 'name'.
|
||||
* @param mixed $value
|
||||
* The value to set, or NULL to unset the field.
|
||||
* @param bool $notify
|
||||
* (optional) Whether to notify the entity of the change. Defaults to
|
||||
* TRUE. If the update stems from the entity, set it to FALSE to avoid
|
||||
* being notified again.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If the specified field does not exist.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set($field_name, $value, $notify = TRUE);
|
||||
|
||||
/**
|
||||
* Gets an array of field item lists.
|
||||
*
|
||||
* @param bool $include_computed
|
||||
* If set to TRUE, computed fields are included. Defaults to TRUE.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldItemListInterface[]
|
||||
* An array of field item lists implementing, keyed by field name.
|
||||
*/
|
||||
public function getFields($include_computed = TRUE);
|
||||
|
||||
/**
|
||||
* Reacts to changes to a field.
|
||||
*
|
||||
* Note that this is invoked after any changes have been applied.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the field which is changed.
|
||||
*/
|
||||
public function onChange($field_name);
|
||||
|
||||
/**
|
||||
* Validates the currently set values.
|
||||
*
|
||||
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
|
||||
* A list of constraint violations. If the list is empty, validation
|
||||
* succeeded.
|
||||
*/
|
||||
public function validate();
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@ namespace Drupal\Core\Entity\KeyValueStore;
|
|||
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 @@ class KeyValueEntityStorage extends EntityStorageBase {
|
|||
$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];
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
|
||||
use Drupal\Component\Utility\String;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\TypedData\EntityDataDefinition;
|
||||
use Drupal\Core\TypedData\ComplexDataInterface;
|
||||
|
@ -83,7 +83,7 @@ class EntityAdapter extends TypedData implements \IteratorAggregate, ComplexData
|
|||
if (!isset($this->entity)) {
|
||||
throw new MissingDataException(String::format('Unable to get property @name as no entity has been provided.', array('@name' => $property_name)));
|
||||
}
|
||||
if (!$this->entity instanceof ContentEntityInterface) {
|
||||
if (!$this->entity instanceof FieldableEntityInterface) {
|
||||
// @todo: Add support for config entities in
|
||||
// https://www.drupal.org/node/1818574.
|
||||
throw new \InvalidArgumentException(String::format('Unable to get unknown property @name.', array('@name' => $property_name)));
|
||||
|
@ -99,7 +99,7 @@ class EntityAdapter extends TypedData implements \IteratorAggregate, ComplexData
|
|||
if (!isset($this->entity)) {
|
||||
throw new MissingDataException(String::format('Unable to set property @name as no entity has been provided.', array('@name' => $property_name)));
|
||||
}
|
||||
if (!$this->entity instanceof ContentEntityInterface) {
|
||||
if (!$this->entity instanceof FieldableEntityInterface) {
|
||||
// @todo: Add support for config entities in
|
||||
// https://www.drupal.org/node/1818574.
|
||||
throw new \InvalidArgumentException(String::format('Unable to set unknown property @name.', array('@name' => $property_name)));
|
||||
|
@ -115,7 +115,7 @@ class EntityAdapter extends TypedData implements \IteratorAggregate, ComplexData
|
|||
if (!isset($this->entity)) {
|
||||
throw new MissingDataException(String::format('Unable to get properties as no entity has been provided.'));
|
||||
}
|
||||
if (!$this->entity instanceof ContentEntityInterface) {
|
||||
if (!$this->entity instanceof FieldableEntityInterface) {
|
||||
// @todo: Add support for config entities in
|
||||
// https://www.drupal.org/node/1818574.
|
||||
return array();
|
||||
|
@ -144,7 +144,7 @@ class EntityAdapter extends TypedData implements \IteratorAggregate, ComplexData
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function onChange($property_name) {
|
||||
if (isset($this->entity) && $this->entity instanceof ContentEntityInterface) {
|
||||
if (isset($this->entity) && $this->entity instanceof FieldableEntityInterface) {
|
||||
// Let the entity know of any changes.
|
||||
$this->entity->onChange($property_name);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class EntityDataDefinition extends ComplexDataDefinitionBase implements EntityDa
|
|||
if ($entity_type_id = $this->getEntityTypeId()) {
|
||||
// Return an empty array for entities that are not content entities.
|
||||
$entity_type_class = \Drupal::entityManager()->getDefinition($entity_type_id)->getClass();
|
||||
if (!in_array('Drupal\Core\Entity\ContentEntityInterface', class_implements($entity_type_class))) {
|
||||
if (!in_array('Drupal\Core\Entity\FieldableEntityInterface', class_implements($entity_type_class))) {
|
||||
$this->propertyDefinitions = array();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Field;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\Entity\BaseFieldOverride;
|
||||
use Drupal\Core\Field\TypedData\FieldItemDataDefinition;
|
||||
use Drupal\Core\TypedData\ListDataDefinition;
|
||||
|
@ -379,7 +379,7 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultValue(ContentEntityInterface $entity) {
|
||||
public function getDefaultValue(FieldableEntityInterface $entity) {
|
||||
// Allow custom default values function.
|
||||
if (!empty($this->definition['default_value_callback'])) {
|
||||
$value = call_user_func($this->definition['default_value_callback'], $entity, $this);
|
||||
|
@ -401,7 +401,7 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
|
|||
* The callback to invoke for getting the default value (pass NULL to unset
|
||||
* a previously set callback). The callback will be invoked with the
|
||||
* following arguments:
|
||||
* - \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* - \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity being created.
|
||||
* - \Drupal\Core\Field\FieldDefinitionInterface $definition
|
||||
* The field definition.
|
||||
|
@ -438,7 +438,7 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOptionsProvider($property_name, ContentEntityInterface $entity) {
|
||||
public function getOptionsProvider($property_name, FieldableEntityInterface $entity) {
|
||||
// If the field item class implements the interface, proxy it through.
|
||||
$item = $entity->get($this->getName())->first();
|
||||
if ($item instanceof OptionsProviderInterface) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Field;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ class EntityReferenceFieldItemList extends FieldItemList implements EntityRefere
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function processDefaultValue($default_value, ContentEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
$default_value = parent::processDefaultValue($default_value, $entity, $definition);
|
||||
|
||||
if ($default_value) {
|
||||
|
|
|
@ -9,8 +9,8 @@ namespace Drupal\Core\Field;
|
|||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||
use Drupal\Core\Config\Entity\ThirdPartySettingsTrait;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\TypedData\FieldItemDataDefinition;
|
||||
|
||||
/**
|
||||
|
@ -153,7 +153,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
|
|||
* The name of a callback function that returns default values.
|
||||
*
|
||||
* The function will be called with the following arguments:
|
||||
* - \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* - \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity being created.
|
||||
* - \Drupal\Core\Field\FieldDefinitionInterface $definition
|
||||
* The field definition.
|
||||
|
@ -332,7 +332,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultValue(ContentEntityInterface $entity) {
|
||||
public function getDefaultValue(FieldableEntityInterface $entity) {
|
||||
// Allow custom default values function.
|
||||
if ($callback = $this->default_value_callback) {
|
||||
$value = call_user_func($callback, $entity, $this);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Field;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\TypedData\ListDataDefinitionInterface;
|
||||
|
||||
/**
|
||||
|
@ -172,7 +172,7 @@ interface FieldDefinitionInterface extends ListDataDefinitionInterface {
|
|||
/**
|
||||
* Returns the default value for the field in a newly created entity.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity for which the default value is generated.
|
||||
*
|
||||
* @return mixed
|
||||
|
@ -185,7 +185,7 @@ interface FieldDefinitionInterface extends ListDataDefinitionInterface {
|
|||
* array.
|
||||
* - NULL or array() for no default value.
|
||||
*/
|
||||
public function getDefaultValue(ContentEntityInterface $entity);
|
||||
public function getDefaultValue(FieldableEntityInterface $entity);
|
||||
|
||||
/**
|
||||
* Returns whether the field is translatable.
|
||||
|
|
|
@ -90,7 +90,7 @@ interface FieldItemInterface extends ComplexDataInterface {
|
|||
/**
|
||||
* Gets the entity that field belongs to.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\ContentEntityInterface
|
||||
* @return \Drupal\Core\Entity\FieldableEntityInterface
|
||||
* The entity object.
|
||||
*/
|
||||
public function getEntity();
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
namespace Drupal\Core\Field;
|
||||
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\TypedData\DataDefinitionInterface;
|
||||
use Drupal\Core\TypedData\Plugin\DataType\ItemList;
|
||||
|
@ -357,7 +357,7 @@ class FieldItemList extends ItemList implements FieldItemListInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function processDefaultValue($default_value, ContentEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
return $default_value;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Field;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Access\AccessibleInterface;
|
||||
|
@ -247,7 +247,7 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
|
|||
*
|
||||
* @param mixed
|
||||
* The default value as defined for the field.
|
||||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity for which the default value is generated.
|
||||
* @param \Drupal\Core\Field\FieldDefinitionInterface $definition
|
||||
* The definition of the field.
|
||||
|
@ -262,6 +262,6 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
|
|||
* array.
|
||||
* - NULL or array() for no default value.
|
||||
*/
|
||||
public static function processDefaultValue($default_value, ContentEntityInterface $entity, FieldDefinitionInterface $definition);
|
||||
public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Field;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
|
||||
/**
|
||||
* Defines an interface for entity field storage definitions.
|
||||
|
@ -137,13 +137,13 @@ interface FieldStorageDefinitionInterface {
|
|||
*
|
||||
* @param string $property_name
|
||||
* The name of the property to get options for; e.g., 'value'.
|
||||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity for which the options should be provided.
|
||||
*
|
||||
* @return \Drupal\Core\TypedData\OptionsProviderInterface|null
|
||||
* An options provider, or NULL if no options are defined.
|
||||
*/
|
||||
public function getOptionsProvider($property_name, ContentEntityInterface $entity);
|
||||
public function getOptionsProvider($property_name, FieldableEntityInterface $entity);
|
||||
|
||||
/**
|
||||
* Returns whether the field can contain multiple items.
|
||||
|
|
|
@ -61,7 +61,7 @@ class EntityReferenceItem extends FieldItemBase {
|
|||
$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')
|
||||
|
@ -102,7 +102,7 @@ class EntityReferenceItem extends FieldItemBase {
|
|||
$target_type = $field_definition->getSetting('target_type');
|
||||
$target_type_info = \Drupal::entityManager()->getDefinition($target_type);
|
||||
|
||||
if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) {
|
||||
if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) {
|
||||
$columns = array(
|
||||
'target_id' => array(
|
||||
'description' => 'The ID of the target entity.',
|
||||
|
|
|
@ -14,9 +14,9 @@ use Drupal\comment\CommentInterface;
|
|||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\comment\CommentManagerInterface;
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\Component\Utility\String;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
@ -366,7 +366,7 @@ function comment_form_field_ui_field_storage_edit_form_alter(&$form, FormStateIn
|
|||
*/
|
||||
function comment_entity_storage_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)) {
|
||||
|
@ -412,7 +412,7 @@ function comment_entity_predelete(EntityInterface $entity) {
|
|||
// mismatched types. So, we need to verify that the ID is numeric (even for an
|
||||
// entity type that has an integer ID, $entity->id() might be a string
|
||||
// containing a number), and then cast it to an integer when querying.
|
||||
if ($entity instanceof ContentEntityInterface && is_numeric($entity->id())) {
|
||||
if ($entity instanceof FieldableEntityInterface && is_numeric($entity->id())) {
|
||||
$entity_query = \Drupal::entityQuery('comment');
|
||||
$entity_query->condition('entity_id', (int) $entity->id());
|
||||
$entity_query->condition('entity_type', $entity->getEntityTypeId());
|
||||
|
|
|
@ -247,7 +247,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) {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace Drupal\comment;
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
@ -66,7 +66,7 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildCommentedEntityLinks(ContentEntityInterface $entity, array &$context) {
|
||||
public function buildCommentedEntityLinks(FieldableEntityInterface $entity, array &$context) {
|
||||
$entity_links = array();
|
||||
$view_mode = $context['view_mode'];
|
||||
if ($view_mode == 'search_index' || $view_mode == 'search_result' || $view_mode == 'print') {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\comment;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
|
||||
/**
|
||||
* Defines an interface for building comment links on a commented entity.
|
||||
|
@ -19,7 +19,7 @@ interface CommentLinkBuilderInterface {
|
|||
/**
|
||||
* Builds links for the given entity.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* Entity for which the links are being built.
|
||||
* @param array $context
|
||||
* Array of context passed from the entity view builder.
|
||||
|
@ -27,6 +27,6 @@ interface CommentLinkBuilderInterface {
|
|||
* @return array
|
||||
* Array of entity links.
|
||||
*/
|
||||
public function buildCommentedEntityLinks(ContentEntityInterface $entity, array &$context);
|
||||
public function buildCommentedEntityLinks(FieldableEntityInterface $entity, array &$context);
|
||||
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ class CommentManager implements CommentManagerInterface {
|
|||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Drupal\comment;
|
|||
|
||||
|
||||
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;
|
||||
|
@ -96,7 +96,7 @@ class CommentStatistics implements CommentStatisticsInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create(ContentEntityInterface $entity, $fields) {
|
||||
public function create(FieldableEntityInterface $entity, $fields) {
|
||||
$query = $this->database->insert('comment_entity_statistics')
|
||||
->fields(array(
|
||||
'entity_id',
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace Drupal\comment;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
|
@ -75,11 +75,11 @@ interface CommentStatisticsInterface {
|
|||
/**
|
||||
* 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);
|
||||
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ namespace Drupal\comment;
|
|||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -131,7 +131,7 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getNewCommentPageNumber($total_comments, $new_comments, ContentEntityInterface $entity, $field_name = 'comment') {
|
||||
public function getNewCommentPageNumber($total_comments, $new_comments, FieldableEntityInterface $entity, $field_name = 'comment') {
|
||||
$field = $entity->getFieldDefinition($field_name);
|
||||
$comments_per_page = $field->getSetting('per_page');
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
namespace Drupal\comment;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
|
||||
/**
|
||||
* Defines an interface for comment entity storage classes.
|
||||
|
@ -46,7 +46,7 @@ interface CommentStorageInterface extends EntityStorageInterface {
|
|||
* The total number of comments that the entity has.
|
||||
* @param int $new_comments
|
||||
* The number of new comments that the entity has.
|
||||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity to which the comments belong.
|
||||
* @param string $field_name
|
||||
* The field name on the entity to which comments are attached.
|
||||
|
@ -54,7 +54,7 @@ interface CommentStorageInterface extends EntityStorageInterface {
|
|||
* @return array|null
|
||||
* The page number where first new comment appears. (First page returns 0.)
|
||||
*/
|
||||
public function getNewCommentPageNumber($total_comments, $new_comments, ContentEntityInterface $entity, $field_name = 'comment');
|
||||
public function getNewCommentPageNumber($total_comments, $new_comments, FieldableEntityInterface $entity, $field_name = 'comment');
|
||||
|
||||
/**
|
||||
* Gets the display ordinal or page number for a comment.
|
||||
|
|
|
@ -29,7 +29,7 @@ class CommentManagerTest extends UnitTestCase {
|
|||
->will($this->returnValue('Node'));
|
||||
$entity_type->expects($this->any())
|
||||
->method('isSubclassOf')
|
||||
->with('\Drupal\Core\Entity\ContentEntityInterface')
|
||||
->with('\Drupal\Core\Entity\FieldableEntityInterface')
|
||||
->will($this->returnValue(TRUE));
|
||||
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace Drupal\datetime\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemList;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
@ -93,7 +93,7 @@ class DateTimeFieldItemList extends FieldItemList {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function processDefaultValue($default_value, ContentEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
$default_value = parent::processDefaultValue($default_value, $entity, $definition);
|
||||
|
||||
if (isset($default_value[0]['default_date_type'])) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
|
@ -320,7 +320,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);
|
||||
|
@ -334,7 +334,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;
|
||||
}
|
||||
|
||||
|
@ -373,7 +373,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);
|
||||
|
@ -387,7 +387,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);
|
||||
|
@ -463,13 +463,13 @@ function _editor_get_file_uuids_by_field(EntityInterface $entity) {
|
|||
/**
|
||||
* Determines the formatted text fields on an entity.
|
||||
*
|
||||
* @param ContentEntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* An entity whose fields to analyze.
|
||||
*
|
||||
* @return array
|
||||
* The names of the fields on this entity that support formatted text.
|
||||
*/
|
||||
function _editor_get_formatted_text_fields(ContentEntityInterface $entity) {
|
||||
function _editor_get_formatted_text_fields(FieldableEntityInterface $entity) {
|
||||
$field_definitions = $entity->getFieldDefinitions();
|
||||
if (empty($field_definitions)) {
|
||||
return array();
|
||||
|
|
|
@ -145,7 +145,7 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements Opt
|
|||
$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 FieldStorageConfigInterface) {
|
||||
if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface') && $field_definition instanceof FieldStorageConfigInterface) {
|
||||
$schema['columns']['revision_id'] = array(
|
||||
'description' => 'The revision ID of the target entity.',
|
||||
'type' => 'int',
|
||||
|
|
|
@ -111,7 +111,7 @@ class SelectionBase implements SelectionInterface {
|
|||
);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -10,8 +10,8 @@ namespace Drupal\field\Entity;
|
|||
use Drupal\Component\Utility\String;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\FieldException;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\TypedData\OptionsProviderInterface;
|
||||
|
@ -585,7 +585,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOptionsProvider($property_name, ContentEntityInterface $entity) {
|
||||
public function getOptionsProvider($property_name, FieldableEntityInterface $entity) {
|
||||
// If the field item class implements the interface, proxy it through.
|
||||
$item = $entity->get($this->getName())->first();
|
||||
if ($item instanceof OptionsProviderInterface) {
|
||||
|
|
|
@ -9,8 +9,8 @@ namespace Drupal\field\Tests\String;
|
|||
|
||||
use Drupal\Component\Utility\String;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
@ -89,7 +89,7 @@ class StringFormatterTest extends KernelTestBase {
|
|||
/**
|
||||
* 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.
|
||||
|
@ -97,7 +97,7 @@ class StringFormatterTest extends KernelTestBase {
|
|||
* @return string
|
||||
* The rendered entity fields.
|
||||
*/
|
||||
protected function renderEntityFields(ContentEntityInterface $entity, EntityViewDisplayInterface $display) {
|
||||
protected function renderEntityFields(FieldableEntityInterface $entity, EntityViewDisplayInterface $display) {
|
||||
$content = $display->build($entity);
|
||||
$content = $this->render($content);
|
||||
return $content;
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Defines a field type and its formatters and widgets.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
|
@ -32,7 +32,7 @@ function field_test_field_storage_config_update_forbid(FieldStorageConfigInterfa
|
|||
/**
|
||||
* Sample 'default value' callback.
|
||||
*/
|
||||
function field_test_default_value(ContentEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
function field_test_default_value(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
return array(array('value' => 99));
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
|
|||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\options\Plugin\Field\FieldWidget;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\WidgetBase;
|
||||
|
@ -114,13 +114,13 @@ abstract class OptionsWidgetBase extends WidgetBase {
|
|||
/**
|
||||
* Returns the array of options for the widget.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity for which to return options.
|
||||
*
|
||||
* @return array
|
||||
* The array of options for the widget.
|
||||
*/
|
||||
protected function getOptions(ContentEntityInterface $entity) {
|
||||
protected function getOptions(FieldableEntityInterface $entity) {
|
||||
if (!isset($this->options)) {
|
||||
// Limit the settable options for the current user account.
|
||||
$options = $this->fieldDefinition
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Field\FieldDefinition;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
|
|
@ -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;
|
||||
|
@ -238,13 +238,13 @@ class QuickEditFieldForm extends FormBase {
|
|||
/**
|
||||
* 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();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* Hooks provided the Entity module.
|
||||
*/
|
||||
|
||||
use Drupal\Component\Utility\String;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface;
|
||||
|
@ -786,7 +786,7 @@ function hook_entity_bundle_delete($entity_type_id, $bundle) {
|
|||
* @see hook_ENTITY_TYPE_create()
|
||||
*/
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\system\Tests\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
|
@ -71,12 +71,12 @@ class FieldTranslationSqlStorageTest extends EntityLanguageTestBase {
|
|||
/**
|
||||
* 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();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
|
@ -422,7 +422,7 @@ function entity_test_entity_test_mul_translation_delete(EntityInterface $transla
|
|||
/**
|
||||
* Field default value callback.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity being created.
|
||||
* @param \Drupal\Core\Field\FieldDefinitionInterface $definition
|
||||
* The field definition.
|
||||
|
@ -433,7 +433,7 @@ function entity_test_entity_test_mul_translation_delete(EntityInterface $transla
|
|||
*
|
||||
* @see \Drupal\field\Entity\FieldConfig::$default_value
|
||||
*/
|
||||
function entity_test_field_default_value(ContentEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
function entity_test_field_default_value(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||
return array(array('value' => $definition->getName() . '_' . $entity->language()->id));
|
||||
}
|
||||
|
||||
|
|
|
@ -716,7 +716,7 @@ class EntityManagerTest extends UnitTestCase {
|
|||
->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\BaseFieldDefinition')
|
||||
->disableOriginalConstructor()
|
||||
|
@ -1039,7 +1039,7 @@ class EntityManagerTest extends UnitTestCase {
|
|||
->will($this->returnValue('test_entity_type'));
|
||||
$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
|
||||
|
@ -1098,7 +1098,7 @@ class EntityManagerTest extends UnitTestCase {
|
|||
$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));
|
||||
|
||||
// Mock the base field definition override.
|
||||
|
@ -1182,7 +1182,7 @@ class EntityManagerTest extends UnitTestCase {
|
|||
->will($this->returnValue('test_entity_type'));
|
||||
$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
|
||||
|
|
Loading…
Reference in New Issue