interface FieldableEntityInterface in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Entity/FieldableEntityInterface.php \Drupal\Core\Entity\FieldableEntityInterface
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.
Hierarchy
- interface \Drupal\Core\Access\AccessibleInterface; interface \Drupal\Core\Cache\CacheableDependencyInterface; interface \Drupal\Core\Cache\RefinableCacheableDependencyInterface
- interface \Drupal\Core\Entity\EntityInterface
- interface \Drupal\Core\Entity\FieldableEntityInterface
- interface \Drupal\Core\Entity\EntityInterface
Expanded class hierarchy of FieldableEntityInterface
All classes that implement FieldableEntityInterface
See also
\Drupal\Core\TypedData\TypedDataManager
\Drupal\Core\Field\FieldItemListInterface
Related topics
45 files declare their use of FieldableEntityInterface
- BaseFieldDefinition.php in core/
lib/ Drupal/ Core/ Field/ BaseFieldDefinition.php - Contains \Drupal\Core\Field\BaseFieldDefinition.
- BooleanFormatterTest.php in core/
modules/ field/ src/ Tests/ Boolean/ BooleanFormatterTest.php - Contains \Drupal\field\Tests\Boolean\BooleanFormatterTest.
- comment.module in core/
modules/ comment/ comment.module - Enables users to comment on published content.
- CommentLinkBuilder.php in core/
modules/ comment/ src/ CommentLinkBuilder.php - Contains \Drupal\comment\CommentLinkBuilder.
- CommentLinkBuilderInterface.php in core/
modules/ comment/ src/ CommentLinkBuilderInterface.php - Contains \Drupal\comment\CommentLinkBuilderInterface.
File
- core/
lib/ Drupal/ Core/ Entity/ FieldableEntityInterface.php, line 28 - Contains \Drupal\Core\Entity\FieldableEntityInterface.
Namespace
Drupal\Core\EntityView source
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);
/**
* Determines 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();
/**
* Gets 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'.
*
* @return \Drupal\Core\Field\FieldItemListInterface
* The field item list, containing the field items.
*
* @throws \InvalidArgumentException
* If an invalid field name is given.
*/
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.
*
* @return $this
*
* @throws \InvalidArgumentException
* If the specified field does not exist.
*/
public function set($field_name, $value, $notify = TRUE);
/**
* Gets an array of all 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);
/**
* Gets an array of field item lists for translatable fields.
*
* @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 getTranslatableFields($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.
*
* @throws \InvalidArgumentException
* When trying to assign a value to the language field that matches an
* existing translation.
* @throws \LogicException
* When trying to change:
* - The language of a translation.
* - The value of the flag identifying the default translation object.
*/
public function onChange($field_name);
/**
* Validates the currently set values.
*
* @return \Drupal\Core\Entity\EntityConstraintViolationListInterface
* A list of constraint violations. If the list is empty, validation
* succeeded.
*/
public function validate();
/**
* Checks whether entity validation is required before saving the entity.
*
* @return bool
* TRUE if validation is required, FALSE if not.
*/
public function isValidationRequired();
/**
* Sets whether entity validation is required before saving the entity.
*
* @param bool $required
* TRUE if validation is required, FALSE otherwise.
*
* @return $this
*/
public function setValidationRequired($required);
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessibleInterface:: |
public | function | Checks data value access. | 5 |
CacheableDependencyInterface:: |
public | function | The cache contexts associated with this object. | 26 |
CacheableDependencyInterface:: |
public | function | The maximum age for which this object may be cached. | 26 |
CacheableDependencyInterface:: |
public | function | The cache tags associated with this object. | 19 |
EntityInterface:: |
public | function | Gets the bundle of the entity. | 2 |
EntityInterface:: |
public static | function | Constructs a new entity object, without permanently saving it. | 2 |
EntityInterface:: |
public | function | Creates a duplicate of the entity. | 2 |
EntityInterface:: |
public | function | Deletes an entity permanently. | 2 |
EntityInterface:: |
public | function | Enforces an entity to be new. | 2 |
EntityInterface:: |
public | function | Returns the cache tags that should be used to invalidate caches. | 2 |
EntityInterface:: |
public | function | Gets the key that is used to store configuration dependencies. | 2 |
EntityInterface:: |
public | function | Gets the configuration dependency name. | 2 |
EntityInterface:: |
public | function | Gets the configuration target identifier for the entity. | 2 |
EntityInterface:: |
public | function | Gets the entity type definition. | 2 |
EntityInterface:: |
public | function | Gets the ID of the type of the entity. | 2 |
EntityInterface:: |
public | function | Gets the original ID. | 2 |
EntityInterface:: |
public | function | Gets a typed data object for this entity object. | 2 |
EntityInterface:: |
public | function | Indicates if a link template exists for a given key. | 2 |
EntityInterface:: |
public | function | Gets the identifier. | 2 |
EntityInterface:: |
public | function | Determines whether the entity is new. | 2 |
EntityInterface:: |
public | function | Gets the label of the entity. | 2 |
EntityInterface:: |
public | function | Gets the language of the entity. | 2 |
EntityInterface:: |
public | function | Deprecated way of generating a link to the entity. See toLink(). | 2 |
EntityInterface:: |
public static | function | Loads an entity. | 2 |
EntityInterface:: |
public static | function | Loads one or more entities. | 2 |
EntityInterface:: |
public | function | Acts on an entity after it is created but before hooks are invoked. | 2 |
EntityInterface:: |
public static | function | Acts on deleted entities before the delete hook is invoked. | 2 |
EntityInterface:: |
public static | function | Acts on loaded entities. | 3 |
EntityInterface:: |
public | function | Acts on a saved entity before the insert or update hook is invoked. | 2 |
EntityInterface:: |
public static | function | Changes the values of an entity before it is created. | 2 |
EntityInterface:: |
public static | function | Acts on entities before they are deleted and before hooks are invoked. | 2 |
EntityInterface:: |
public | function | Acts on an entity before the presave hook is invoked. | 2 |
EntityInterface:: |
public | function | Gets a list of entities referenced by this entity. | 2 |
EntityInterface:: |
public | function | Saves an entity permanently. | 2 |
EntityInterface:: |
public | function | Sets the original ID. | 2 |
EntityInterface:: |
public | function | Generates the HTML for a link to this entity. | 2 |
EntityInterface:: |
public | function | Gets the URL object for the entity. | 2 |
EntityInterface:: |
public | function | Gets a list of URI relationships supported by this entity. | 2 |
EntityInterface:: |
public | function | Gets the public URL for this entity. | 2 |
EntityInterface:: |
public | function | Gets the URL object for the entity. | 2 |
EntityInterface:: |
public | function | Gets the entity UUID (Universally Unique Identifier). | 2 |
FieldableEntityInterface:: |
public static | function | Provides base field definitions for an entity type. | 14 |
FieldableEntityInterface:: |
public static | function | Provides field definitions for a specific bundle. | 2 |
FieldableEntityInterface:: |
public | function | Gets a field item list. | 1 |
FieldableEntityInterface:: |
public | function | Gets the definition of a contained field. | 1 |
FieldableEntityInterface:: |
public | function | Gets an array of field definitions of all contained fields. | 1 |
FieldableEntityInterface:: |
public | function | Gets an array of all field item lists. | 1 |
FieldableEntityInterface:: |
public | function | Gets an array of field item lists for translatable fields. | 1 |
FieldableEntityInterface:: |
public | function | Determines whether the entity has a field with the given name. | 1 |
FieldableEntityInterface:: |
public | function | Checks whether entity validation is required before saving the entity. | 1 |
FieldableEntityInterface:: |
public | function | Reacts to changes to a field. | 1 |
FieldableEntityInterface:: |
public | function | Sets a field value. | 1 |
FieldableEntityInterface:: |
public | function | Sets whether entity validation is required before saving the entity. | 1 |
FieldableEntityInterface:: |
public | function |
Gets an array of all field values. Overrides EntityInterface:: |
|
FieldableEntityInterface:: |
public | function | Validates the currently set values. | 1 |
RefinableCacheableDependencyInterface:: |
public | function | Adds a dependency on an object: merges its cacheability metadata. | 1 |
RefinableCacheableDependencyInterface:: |
public | function | Adds cache contexts. | 1 |
RefinableCacheableDependencyInterface:: |
public | function | Adds cache tags. | 1 |
RefinableCacheableDependencyInterface:: |
public | function | Merges the maximum age (in seconds) with the existing maximum age. | 1 |