Drupal 8  8.0.2
FieldableEntityInterface Interface Reference
Inheritance diagram for FieldableEntityInterface:

Public Member Functions

 hasField ($field_name)
 
 getFieldDefinition ($name)
 
 getFieldDefinitions ()
 
 toArray ()
 
 get ($field_name)
 
 set ($field_name, $value, $notify=TRUE)
 
 getFields ($include_computed=TRUE)
 
 getTranslatableFields ($include_computed=TRUE)
 
 onChange ($field_name)
 
 validate ()
 
 isValidationRequired ()
 
 setValidationRequired ($required)
 
- Public Member Functions inherited from EntityInterface
 uuid ()
 
 id ()
 
 language ()
 
 isNew ()
 
 enforceIsNew ($value=TRUE)
 
 getEntityTypeId ()
 
 bundle ()
 
 label ()
 
 urlInfo ($rel= 'canonical', array $options=array())
 
 toUrl ($rel= 'canonical', array $options=array())
 
 url ($rel= 'canonical', $options=array())
 
 link ($text=NULL, $rel= 'canonical', array $options=[])
 
 toLink ($text=NULL, $rel= 'canonical', array $options=[])
 
 hasLinkTemplate ($key)
 
 uriRelationships ()
 
 save ()
 
 delete ()
 
 preSave (EntityStorageInterface $storage)
 
 postSave (EntityStorageInterface $storage, $update=TRUE)
 
 postCreate (EntityStorageInterface $storage)
 
 createDuplicate ()
 
 getEntityType ()
 
 referencedEntities ()
 
 getOriginalId ()
 
 getCacheTagsToInvalidate ()
 
 setOriginalId ($id)
 
 getTypedData ()
 
 getConfigDependencyKey ()
 
 getConfigDependencyName ()
 
 getConfigTarget ()
 
- Public Member Functions inherited from AccessibleInterface
 access ($operation, AccountInterface $account=NULL, $return_as_object=FALSE)
 
- Public Member Functions inherited from CacheableDependencyInterface
 getCacheContexts ()
 
 getCacheTags ()
 
 getCacheMaxAge ()
 
- Public Member Functions inherited from RefinableCacheableDependencyInterface
 addCacheContexts (array $cache_contexts)
 
 addCacheTags (array $cache_tags)
 
 mergeCacheMaxAge ($max_age)
 
 addCacheableDependency ($other_object)
 

Static Public Member Functions

static baseFieldDefinitions (EntityTypeInterface $entity_type)
 
static bundleFieldDefinitions (EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)
 
- Static Public Member Functions inherited from EntityInterface
static load ($id)
 
static loadMultiple (array $ids=NULL)
 
static create (array $values=array())
 
static preCreate (EntityStorageInterface $storage, array &$values)
 
static preDelete (EntityStorageInterface $storage, array $entities)
 
static postDelete (EntityStorageInterface $storage, array $entities)
 
static postLoad (EntityStorageInterface $storage, array &$entities)
 

Detailed Description

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 , 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 Also

Member Function Documentation

static baseFieldDefinitions ( EntityTypeInterface  $entity_type)
static

Provides base field definitions for an entity type.

Implementations typically use the class for creating the field definitions; for example a 'name' field could be defined as the following:

$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'));

By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use ::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.

Parameters
\Drupal\Core\Entity\EntityTypeInterface$entity_typeThe entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.
Returns
[] An array of base field definitions for the entity type, keyed by field name.
See Also
::getFieldDefinitions()
::bundleFieldDefinitions()

Implemented in EntityManagerTestEntity, User, MenuLinkContent, BlockContent, Message, Term, EntityTest, EntityTestMulChanged, EntityTestMulRevChanged, EntityTestRev, EntityTestMulLangcodeKey, EntityTestMulDefaultValue, EntityTestBaseFieldDisplay, EntityTestStringId, EntityTestCompositeConstraint, EntityTestConstraints, EntityTestUpdate, EntityTestConstraintViolation, NoLanguageEntityTest, EntityTestDefaultValue, and EntityTestFieldOverride.

static bundleFieldDefinitions ( EntityTypeInterface  $entity_type,
  $bundle,
array  $base_field_definitions 
)
static

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.

Parameters
\Drupal\Core\Entity\EntityTypeInterface$entity_typeThe entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.
string$bundleThe bundle.
\Drupal\Core\Field\FieldDefinitionInterface[]$base_field_definitions The list of base field definitions.
Returns
[] An array of bundle field definitions, keyed by field name.
See Also
::getFieldDefinitions()
::baseFieldDefinitions()
Todo:
WARNING: This method will be changed in https://www.drupal.org/node/2346347.

Implemented in ContentEntityBase, EntityManagerTestEntity, EntityTestUpdate, and EntityTestFieldOverride.

get (   $field_name)

Gets a field item list.

Parameters
string$field_nameThe name of the field to get; e.g., 'title' or 'name'.
Returns
The field item list, containing the field items.
Exceptions
\InvalidArgumentExceptionIf an invalid field name is given.

Implemented in ContentEntityBase.

Referenced by CommentValidationTest\assertLengthViolation(), StandardProfileTest\assertRdfaCommonNodeProperties(), EntityFormDisplay\buildForm(), EntityFormDisplay\flagWidgetsErrorsFromViolations(), BaseFieldDefinition\getOptionsProvider(), FieldStorageConfig\getOptionsProvider(), and ContentEntityStorageBase\initFieldValues().

Here is the caller graph for this function:

getFieldDefinition (   $name)

Gets the definition of a contained field.

Parameters
string$nameThe name of the field.
Returns
|null The definition of the field or null if the field does not exist.

Implemented in ContentEntityBase.

getFieldDefinitions ( )

Gets an array of field definitions of all contained fields.

Returns
[] An array of field definitions, keyed by field name.
See Also
::getFieldDefinitions()

Implemented in ContentEntityBase.

getFields (   $include_computed = TRUE)

Gets an array of all field item lists.

Parameters
bool$include_computedIf set to TRUE, computed fields are included. Defaults to TRUE.
Returns
[] An array of field item lists implementing, keyed by field name.

Implemented in ContentEntityBase.

getTranslatableFields (   $include_computed = TRUE)

Gets an array of field item lists for translatable fields.

Parameters
bool$include_computedIf set to TRUE, computed fields are included. Defaults to TRUE.
Returns
[] An array of field item lists implementing, keyed by field name.

Implemented in ContentEntityBase.

hasField (   $field_name)

Determines whether the entity has a field with the given name.

Parameters
string$field_nameThe field name.
Returns
bool TRUE if the entity has a field with the given name. FALSE otherwise.

Implemented in ContentEntityBase.

isValidationRequired ( )

Checks whether entity validation is required before saving the entity.

Returns
bool TRUE if validation is required, FALSE if not.

Implemented in ContentEntityBase.

onChange (   $field_name)

Reacts to changes to a field.

Note that this is invoked after any changes have been applied.

Parameters
string$field_nameThe name of the field which is changed.
Exceptions
\InvalidArgumentExceptionWhen trying to assign a value to the language field that matches an existing translation.
\LogicExceptionWhen trying to change:
  • The language of a translation.
  • The value of the flag identifying the default translation object.

Implemented in ContentEntityBase.

set (   $field_name,
  $value,
  $notify = TRUE 
)

Sets a field value.

Parameters
string$field_nameThe name of the field to set; e.g., 'title' or 'name'.
mixed$valueThe value to set, or NULL to unset the field.
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.
Returns
$this
Exceptions
\InvalidArgumentExceptionIf the specified field does not exist.

Implemented in ContentEntityBase.

Referenced by RESTTestBase\removeNodeFieldsForNonAdminUsers().

Here is the caller graph for this function:

setValidationRequired (   $required)

Sets whether entity validation is required before saving the entity.

Parameters
bool$requiredTRUE if validation is required, FALSE otherwise.
Returns
$this

Implemented in ContentEntityBase.

toArray ( )

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.

Returns
array An array of field values, keyed by field name.

Implements EntityInterface.

Implemented in ContentEntityBase.

validate ( )

Validates the currently set values.

Returns
A list of constraint violations. If the list is empty, validation succeeded.

Implemented in ContentEntityBase.

Referenced by CommentValidationTest\assertLengthViolation().

Here is the caller graph for this function:


The documentation for this interface was generated from the following file: