interface FieldConfigInterface implements FieldDefinitionInterface, ConfigEntityInterface (View source)

Defines an interface for configurable field definitions.

This interface allows both configurable fields and overridden base fields to share a common interface. The interface also extends ConfigEntityInterface to ensure that implementations have the expected save() method.

Methods

createFromDataType(string $data_type)

Creates a new data definition object.

string
getDataType()

Returns the data type of the data.

getLabel()

Returns a human readable label.

string|null
getDescription()

Returns a human readable description.

bool
isList()

Returns whether the data is multi-valued, i.e. a list of data items.

bool
isReadOnly()

Determines whether the data is read-only.

bool
isComputed()

Determines whether the data value is computed.

bool
isRequired()

Determines whether a data value is required.

string
getClass()

Returns the class used for creating the typed data object.

array
getSettings()

Returns the array of settings, as required by the used class.

mixed
getSetting(string $setting_name)

Returns the value of a given setting.

array[]
getConstraints()

Returns an array of validation constraints.

array
getConstraint(string $constraint_name)

Returns a validation constraint.

addConstraint(string $constraint_name, array|null $options = NULL)

Adds a validation constraint to the FieldItemList.

bool
isInternal()

Determines whether the data value is internal.

createFromItemType(string $item_type)

Creates a new list data definition for items of the given data type.

getItemDefinition()

Gets the data definition of an item of the list.

string[]
getCacheContexts()

The cache contexts associated with this object.

string[]
getCacheTags()

The cache tags associated with this object.

int
getCacheMaxAge()

The maximum age for which this object may be cached.

string
getName()

Returns the machine name of the field.

string
getType()

Returns the field type.

string
getTargetEntityTypeId()

Returns the ID of the entity type the field is attached to.

string|null
getTargetBundle()

Gets the bundle the field is attached to.

bool
isDisplayConfigurable(string $display_context)

Returns whether the display for the field can be configured.

array|null
getDisplayOptions(string $display_context)

Returns the default display options for the field.

array
getDefaultValueLiteral()

Returns the default value literal for the field.

string|null
getDefaultValueCallback()

Returns the default value callback for the field.

array
getDefaultValue(FieldableEntityInterface $entity)

Returns the default value for the field in a newly created entity.

bool
isTranslatable()

Returns whether the field is translatable.

getConfig(string $bundle)

Gets an object that can be saved in configuration.

string
getUniqueIdentifier()

Returns a unique identifier for the field.

access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)

Checks data value access.

$this
addCacheContexts(array $cache_contexts)

Adds cache contexts.

$this
addCacheTags(array $cache_tags)

Adds cache tags.

$this
mergeCacheMaxAge(int $max_age)

Merges the maximum age (in seconds) with the existing maximum age.

$this
addCacheableDependency(CacheableDependencyInterface|object $other_object)

Adds a dependency on an object: merges its cacheability metadata.

string|null
uuid()

Gets the entity UUID (Universally Unique Identifier).

string|int|null
id()

Gets the identifier.

language()

Gets the language of the entity.

bool
isNew()

Determines whether the entity is new.

$this
enforceIsNew(bool $value = TRUE)

Enforces an entity to be new.

string
getEntityTypeId()

Gets the ID of the type of the entity.

string
bundle()

Gets the bundle of the entity.

string|TranslatableMarkup|null
label()

Gets the label of the entity.

Url
toUrl(string $rel = 'canonical', array $options = [])

Gets the URL object for the entity.

toLink(string|null $text = NULL, string $rel = 'canonical', array $options = [])

Generates the HTML for a link to this entity.

bool
hasLinkTemplate(string $key)

Indicates if a link template exists for a given key.

string[]
uriRelationships()

Gets a list of URI relationships supported by this entity.

static EntityInterface|null
load(mixed $id)

Loads an entity.

static EntityInterface[]
loadMultiple(array $ids = NULL)

Loads one or more entities.

static EntityInterface
create(array $values = [])

Constructs a new entity object, without permanently saving it.

int
save()

Saves an entity permanently.

delete()

Deletes an entity permanently.

preSave(EntityStorageInterface $storage)

Acts on an entity before the presave hook is invoked.

postSave(EntityStorageInterface $storage, bool $update = TRUE)

Acts on a saved entity before the insert or update hook is invoked.

static 
preCreate(EntityStorageInterface $storage, array $values)

Changes the values of an entity before it is created.

postCreate(EntityStorageInterface $storage)

Acts on a created entity before hooks are invoked.

static 
preDelete(EntityStorageInterface $storage, array $entities)

Acts on entities before they are deleted and before hooks are invoked.

static 
postDelete(EntityStorageInterface $storage, array $entities)

Acts on deleted entities before the delete hook is invoked.

static 
postLoad(EntityStorageInterface $storage, array $entities)

Acts on loaded entities.

createDuplicate()

Creates a duplicate of the entity.

getEntityType()

Gets the entity type definition.

referencedEntities()

Gets a list of entities referenced by this entity.

int|string|null
getOriginalId()

Gets the original ID.

string[]
getCacheTagsToInvalidate()

Returns the cache tags that should be used to invalidate caches.

$this
setOriginalId(int|string|null $id)

Sets the original ID.

array
toArray()

Gets an array of all property values.

getTypedData()

Gets a typed data object for this entity object.

string
getConfigDependencyKey()

Gets the key that is used to store configuration dependencies.

string
getConfigDependencyName()

Gets the configuration dependency name.

string
getConfigTarget()

Gets the configuration target identifier for the entity.

$this
setThirdPartySetting(string $module, string $key, mixed $value)

Sets the value of a third-party setting.

mixed
getThirdPartySetting(string $module, string $key, mixed $default = NULL)

Gets the value of a third-party setting.

array
getThirdPartySettings(string $module)

Gets all third-party settings of a given module.

mixed
unsetThirdPartySetting(string $module, string $key)

Unsets a third-party setting.

array
getThirdPartyProviders()

Gets the list of third parties that store information.

$this
setSyncing(bool $status)

Sets the status of the synchronization flag.

bool
isSyncing()

Returns whether this entity is being changed as part of a synchronization.

$this
enable()

Enables the configuration entity.

$this
disable()

Disables the configuration entity.

$this
setStatus(bool $status)

Sets the status of the configuration entity.

bool
status()

Returns whether the configuration entity is enabled.

bool
isUninstalling()

Returns whether this entity is being changed during the uninstall process.

mixed
get(string $property_name)

Returns the value of a property.

$this
set(string $property_name, mixed $value)

Sets the value of a property.

$this
calculateDependencies()

Calculates dependencies and stores them in the dependency property.

bool
onDependencyRemoval(array $dependencies)

Informs the entity that entities it depends on will be deleted.

array
getDependencies()

Gets the configuration dependencies.

bool
isInstallable()

Checks whether this entity is installable.

$this
trustData()

Sets that the data should be trusted.

bool
hasTrustedData()

Gets whether on not the data is trusted.

$this
setLabel(string $label)

Sets the field definition label.

$this
setDescription(string $description)

Sets a human readable description.

$this
setTranslatable(bool $translatable)

Sets whether the field is translatable.

$this
setSettings(array $settings)

Sets field settings.

$this
setSetting(string $setting_name, mixed $value)

Sets the value for a field setting by name.

$this
setRequired(bool $required)

Sets whether the field can be empty.

$this
setDefaultValue(mixed $value)

Sets a default value.

$this
setDefaultValueCallback(string|null $callback)

Sets a custom default value callback.

setPropertyConstraints(string $name, array $constraints)

Sets constraints for a given field item property.

addPropertyConstraints(string $name, array $constraints)

Adds constraints for a given field item property.

$this
setConstraints(array $constraints)

Sets the array of validation constraints for the FieldItemList.

Details

static DataDefinitionInterface createFromDataType(string $data_type)

Creates a new data definition object.

This method is typically used by \Drupal\Core\TypedData\TypedDataManager::createDataDefinition() to build a definition object for an arbitrary data type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.:

Parameters

string $data_type

The data type, for which a data definition should be created.

Return Value

DataDefinitionInterface

Exceptions

InvalidArgumentException

string getDataType()

Returns the data type of the data.

Return Value

string

The data type.

string|TranslatableMarkup getLabel()

Returns a human readable label.

Return Value

string|TranslatableMarkup

The label. A string or an instance of TranslatableMarkup will be returned based on the way the label translation is handled.

string|null getDescription()

Returns a human readable description.

Descriptions are usually used on user interfaces where the data is edited or displayed.

Return Value

string|null

The description, or NULL if no description is available.

bool isList()

Returns whether the data is multi-valued, i.e. a list of data items.

This is equivalent to checking whether the data definition implements the \Drupal\Core\TypedData\ListDefinitionInterface interface.

Return Value

bool

Whether the data is multi-valued.

bool isReadOnly()

Determines whether the data is read-only.

Return Value

bool

Whether the data is read-only.

bool isComputed()

Determines whether the data value is computed.

For example, data could be computed depending on some other values.

Return Value

bool

Whether the data value is computed.

bool isRequired()

Determines whether a data value is required.

For required data a non-NULL value is mandatory.

Return Value

bool

Whether a data value is required.

string getClass()

Returns the class used for creating the typed data object.

If not specified, the default class of the data type will be returned.

Return Value

string

The class used for creating the typed data object.

array getSettings()

Returns the array of settings, as required by the used class.

See the documentation of the class for supported or required settings.

Return Value

array

The array of settings.

mixed getSetting(string $setting_name)

Returns the value of a given setting.

Parameters

string $setting_name

The setting name.

Return Value

mixed

The setting value.

array[] getConstraints()

Returns an array of validation constraints.

The validation constraints of a definition consist of any for it defined constraints and default constraints, which are generated based on the definition and its data type. See \Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints().

Constraints are defined via an array, having constraint plugin IDs as key and constraint options as values, e.g.

Return Value

array[]

An array of validation constraint definitions, keyed by constraint name. Each constraint definition can be used for instantiating \Symfony\Component\Validator\Constraint objects.

See also

ConstraintManager
Constraint

array getConstraint(string $constraint_name)

Returns a validation constraint.

See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.

Parameters

string $constraint_name

The name of the constraint, i.e. its plugin id.

Return Value

array

A validation constraint definition which can be used for instantiating a \Symfony\Component\Validator\Constraint object.

See also

Constraint

DataDefinitionInterface addConstraint(string $constraint_name, array|null $options = NULL)

Adds a validation constraint to the FieldItemList.

Note: If you wish to apply a constraint to just a property of a FieldItem use \Drupal\Core\Field\FieldConfigInterface::addPropertyConstraints() instead.

Parameters

string $constraint_name

The name of the constraint to add, i.e. its plugin id.

array|null $options

The constraint options as required by the constraint plugin, or NULL.

Return Value

DataDefinitionInterface

The object itself for chaining.

See also

FieldItemList
FieldConfigInterface::addPropertyConstraints
hook_entity_bundle_field_info_alter()

bool isInternal()

Determines whether the data value is internal.

This can be used in a scenario when it is not desirable to expose this data value to an external system.

The implications of this method are left to the discretion of the caller. For example, a module providing an HTTP API may not expose entities of this type, or a custom entity reference field settings form may deprioritize entities of this type in a select list.

Return Value

bool

Whether the data value is internal.

static ListDataDefinitionInterface createFromItemType(string $item_type)

Creates a new list data definition for items of the given data type.

This method is typically used by \Drupal\Core\TypedData\TypedDataManager::createListDataDefinition() to build a definition object for an arbitrary item type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.:

Parameters

string $item_type

The item type, for which a list data definition should be created.

Return Value

ListDataDefinitionInterface

Exceptions

InvalidArgumentException

DataDefinitionInterface getItemDefinition()

Gets the data definition of an item of the list.

Return Value

DataDefinitionInterface

A data definition describing the list items.

string[] getCacheContexts()

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return Value

string[]

An array of cache context tokens, used to generate a cache ID.

See also

CacheContextsManager::convertTokensToKeys

string[] getCacheTags()

The cache tags associated with this object.

When this object is modified, these cache tags will be invalidated.

Return Value

string[]

A set of cache tags.

int getCacheMaxAge()

The maximum age for which this object may be cached.

Return Value

int

The maximum time in seconds that this object may be cached.

string getName()

Returns the machine name of the field.

This defines how the field data is accessed from the entity. For example, if the field name is "foo", then $entity->foo returns its data.

Return Value

string

The field name.

string getType()

Returns the field type.

Return Value

string

The field type, i.e. the id of a field type plugin. For example 'text'.

See also

FieldTypePluginManagerInterface

string getTargetEntityTypeId()

Returns the ID of the entity type the field is attached to.

This method should not be confused with EntityInterface::getEntityTypeId() (configurable fields are config entities, and thus implement both interfaces):

  • FieldDefinitionInterface::getTargetEntityTypeId() answers "as a field, which entity type are you attached to?".
  • EntityInterface::getEntityTypeId() answers "as a (config) entity, what is your own entity type?".

Return Value

string

The entity type ID.

string|null getTargetBundle()

Gets the bundle the field is attached to.

This method should not be confused with EntityInterface::bundle() (configurable fields are config entities, and thus implement both interfaces):

  • FieldDefinitionInterface::getTargetBundle() answers "as a field, which bundle are you attached to?".
  • EntityInterface::bundle() answers "as a (config) entity, what is your own bundle?" (not relevant in our case, the config entity types used to store the definitions of configurable fields do not have bundles).

Return Value

string|null

The bundle the field is defined for, or NULL if it is a base field; i.e., it is not bundle-specific.

bool isDisplayConfigurable(string $display_context)

Returns whether the display for the field can be configured.

Parameters

string $display_context

The display context. Either 'view' or 'form'.

Return Value

bool

TRUE if the display for this field is configurable in the given context. If TRUE, the display options returned by getDisplayOptions() may be overridden via the respective entity display.

See also

EntityDisplayInterface

array|null getDisplayOptions(string $display_context)

Returns the default display options for the field.

If the field's display is configurable, the returned display options act as default values and may be overridden via the respective entity display. Otherwise, the display options will be applied to entity displays as is.

Parameters

string $display_context

The display context. Either 'view' or 'form'.

Return Value

array|null

The array of display options for the field, or NULL if the field is not displayed. The following key/value pairs may be present:

  • label: (string) Position of the field label. The default 'field' theme implementation supports the values 'inline', 'above' and 'hidden'. Defaults to 'above'. Only applies to 'view' context.
  • region: (string) The region the field is in, or 'hidden'. If not specified, the default region will be used.
  • type: (string) The plugin (widget or formatter depending on $display_context) to use. If not specified or if the requested plugin is unknown, the 'default_widget' / 'default_formatter' for the field type will be used. Previously 'hidden' was a valid value, it is now deprecated in favor of specifying 'region' => 'hidden'.
  • settings: (array) Settings for the plugin specified above. The default settings for the plugin will be used for settings left unspecified.
  • third_party_settings: (array) Settings provided by other extensions through hook_field_formatter_third_party_settings_form().
  • weight: (float) The weight of the element. Not needed if 'type' is 'hidden'. The defaults of the various display options above get applied by the used entity display.

See also

EntityDisplayInterface

array getDefaultValueLiteral()

Returns the default value literal for the field.

This method retrieves the raw property assigned to the field definition. When computing the runtime default value for a field in a given entity, ::getDefaultValue() should be used instead.

Return Value

array

The default value for the field, as a numerically indexed array of items, each item being a property/value array (array() for no default value).

See also

FieldDefinitionInterface::getDefaultValue
FieldDefinitionInterface::getDefaultValueCallback

string|null getDefaultValueCallback()

Returns the default value callback for the field.

This method retrieves the raw property assigned to the field definition. When computing the runtime default value for a field in a given entity, ::getDefaultValue() should be used instead.

Return Value

string|null

The default value callback for the field.

See also

FieldDefinitionInterface::getDefaultValue
FieldDefinitionInterface::getDefaultValueLiteral

array getDefaultValue(FieldableEntityInterface $entity)

Returns the default value for the field in a newly created entity.

This method computes the runtime default value for a field in a given entity. To access the raw properties assigned to the field definition, ::getDefaultValueLiteral() or ::getDefaultValueCallback() should be used instead.

Parameters

FieldableEntityInterface $entity

The entity for which the default value is generated.

Return Value

array

The default value for the field, as a numerically indexed array of items, each item being a property/value array (array() for no default value).

See also

FieldDefinitionInterface::getDefaultValueLiteral
FieldDefinitionInterface::getDefaultValueCallback

bool isTranslatable()

Returns whether the field is translatable.

Return Value

bool

TRUE if the field is translatable.

FieldStorageDefinitionInterface getFieldStorageDefinition()

Returns the field storage definition.

Return Value

FieldStorageDefinitionInterface

The field storage definition.

FieldConfigInterface getConfig(string $bundle)

Gets an object that can be saved in configuration.

Base fields are defined in code. In order to configure field definition properties per bundle use this method to create an override that can be saved in configuration.

Parameters

string $bundle

The bundle to get the configurable field for.

Return Value

FieldConfigInterface

See also

BaseFieldBundleOverride

string getUniqueIdentifier()

Returns a unique identifier for the field.

Return Value

string

bool|AccessResultInterface access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)

Checks data value access.

Parameters

string $operation

The operation to be performed.

AccountInterface $account

(optional) The user for which to check access, or NULL to check access for the current user. Defaults to NULL.

bool $return_as_object

(optional) Defaults to FALSE.

Return Value

bool|AccessResultInterface

The access result. Returns a boolean if $return_as_object is FALSE (this is the default) and otherwise an AccessResultInterface object. When a boolean is returned, the result of AccessInterface::isAllowed() is returned, i.e. TRUE means access is explicitly allowed, FALSE means access is either explicitly forbidden or "no opinion".

$this addCacheContexts(array $cache_contexts)

Adds cache contexts.

Parameters

array $cache_contexts

The cache contexts to be added.

Return Value

$this

$this addCacheTags(array $cache_tags)

Adds cache tags.

Parameters

array $cache_tags

The cache tags to be added.

Return Value

$this

$this mergeCacheMaxAge(int $max_age)

Merges the maximum age (in seconds) with the existing maximum age.

The max age will be set to the given value if it is lower than the existing value.

Parameters

int $max_age

The max age to associate.

Return Value

$this

Exceptions

InvalidArgumentException

$this addCacheableDependency(CacheableDependencyInterface|object $other_object)

Adds a dependency on an object: merges its cacheability metadata.

Parameters

CacheableDependencyInterface|object $other_object

The dependency. If the object implements CacheableDependencyInterface, then its cacheability metadata will be used. Otherwise, the passed in object must be assumed to be uncacheable, so max-age 0 is set.

Return Value

$this

See also

CacheableMetadata::createFromObject

string|null uuid()

Gets the entity UUID (Universally Unique Identifier).

The UUID is guaranteed to be unique and can be used to identify an entity across multiple systems.

Return Value

string|null

The UUID of the entity, or NULL if the entity does not have one.

string|int|null id()

Gets the identifier.

Return Value

string|int|null

The entity identifier, or NULL if the object does not yet have an identifier.

LanguageInterface language()

Gets the language of the entity.

Return Value

LanguageInterface

The language object.

bool isNew()

Determines whether the entity is new.

Usually an entity is new if no ID exists for it yet. However, entities may be enforced to be new with existing IDs too.

Return Value

bool

TRUE if the entity is new, or FALSE if the entity has already been saved.

See also

EntityInterface::enforceIsNew

$this enforceIsNew(bool $value = TRUE)

Enforces an entity to be new.

Allows migrations to create entities with pre-defined IDs by forcing the entity to be new before saving.

Parameters

bool $value

(optional) Whether the entity should be forced to be new. Defaults to TRUE.

Return Value

$this

See also

EntityInterface::isNew

string getEntityTypeId()

Gets the ID of the type of the entity.

Return Value

string

The entity type ID.

string bundle()

Gets the bundle of the entity.

Return Value

string

The bundle of the entity. Defaults to the entity type ID if the entity type does not make use of different bundles.

string|TranslatableMarkup|null label()

Gets the label of the entity.

Return Value

string|TranslatableMarkup|null

The label of the entity, or NULL if there is no label defined.

Url toUrl(string $rel = 'canonical', array $options = [])

Gets the URL object for the entity.

The entity must have an id already. Content entities usually get their IDs by saving them.

URI templates might be set in the links array in an annotation, for example:

Parameters

string $rel

The link relationship type, for example: canonical or edit-form.

array $options

See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for the available options.

Return Value

Url

The URL object.

Exceptions

EntityMalformedException
UndefinedLinkTemplateException

Generates the HTML for a link to this entity.

Parameters

string|null $text

(optional) The link text for the anchor tag as a translated string. If NULL, it will use the entity's label. Defaults to NULL.

string $rel

(optional) The link relationship type. Defaults to 'canonical'.

array $options

See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for the available options.

Return Value

Link

A Link to the entity.

Exceptions

EntityMalformedException
UndefinedLinkTemplateException

bool hasLinkTemplate(string $key)

Indicates if a link template exists for a given key.

Parameters

string $key

The link type.

Return Value

bool

TRUE if the link template exists, FALSE otherwise.

string[] uriRelationships()

Gets a list of URI relationships supported by this entity.

Return Value

string[]

An array of link relationships supported by this entity.

static EntityInterface|null load(mixed $id)

Loads an entity.

Parameters

mixed $id

The id of the entity to load.

Return Value

EntityInterface|null

The entity object or NULL if there is no entity with the given ID.

static EntityInterface[] loadMultiple(array $ids = NULL)

Loads one or more entities.

Parameters

array $ids

An array of entity IDs, or NULL to load all entities.

Return Value

EntityInterface[]

An array of entity objects indexed by their IDs.

static EntityInterface create(array $values = [])

Constructs a new entity object, without permanently saving it.

Parameters

array $values

(optional) An array of values to set, keyed by property name. If the entity type has bundles, the bundle key has to be specified.

Return Value

EntityInterface

The entity object.

int save()

Saves an entity permanently.

When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.

Return Value

int

Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Exceptions

EntityStorageException

delete()

Deletes an entity permanently.

preSave(EntityStorageInterface $storage)

Acts on an entity before the presave hook is invoked.

Used before the entity is saved and before invoking the presave hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed. This is different from its counterpart in the Field API, FieldItemListInterface::preSave(), which is fired on all field translations automatically.

Adjust existing implementations and the documentation according to https://www.drupal.org/node/2577609 to have a consistent API.

Parameters

EntityStorageInterface $storage

The entity storage object.

Exceptions

Exception

See also

FieldItemListInterface::preSave

postSave(EntityStorageInterface $storage, bool $update = TRUE)

Acts on a saved entity before the insert or update hook is invoked.

Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters

EntityStorageInterface $storage

The entity storage object.

bool $update

TRUE if the entity has been updated, or FALSE if it has been inserted.

static preCreate(EntityStorageInterface $storage, array $values)

Changes the values of an entity before it is created.

Load defaults for example.

Parameters

EntityStorageInterface $storage

The entity storage object.

array $values

An array of values to set, keyed by property name. If the entity type has bundles the bundle key has to be specified.

postCreate(EntityStorageInterface $storage)

Acts on a created entity before hooks are invoked.

Used after the entity is created, but before saving the entity and before any of the presave hooks are invoked.

See the @link entity_crud Entity CRUD topic @endlink for more information.

Parameters

EntityStorageInterface $storage

The entity storage object.

See also

EntityInterface::create

static preDelete(EntityStorageInterface $storage, array $entities)

Acts on entities before they are deleted and before hooks are invoked.

Used before the entities are deleted and before invoking the delete hook.

Parameters

EntityStorageInterface $storage

The entity storage object.

array $entities

An array of entities.

static postDelete(EntityStorageInterface $storage, array $entities)

Acts on deleted entities before the delete hook is invoked.

Used after the entities are deleted but before invoking the delete hook.

Parameters

EntityStorageInterface $storage

The entity storage object.

array $entities

An array of entities.

static postLoad(EntityStorageInterface $storage, array $entities)

Acts on loaded entities.

Parameters

EntityStorageInterface $storage

The entity storage object.

array $entities

An array of entities.

EntityInterface createDuplicate()

Creates a duplicate of the entity.

Return Value

EntityInterface

A clone of $this with all identifiers unset, so saving it inserts a new entity into the storage system.

EntityTypeInterface getEntityType()

Gets the entity type definition.

Return Value

EntityTypeInterface

The entity type definition.

EntityInterface[] referencedEntities()

Gets a list of entities referenced by this entity.

Return Value

EntityInterface[]

An array of entities.

int|string|null getOriginalId()

Gets the original ID.

Return Value

int|string|null

The original ID, or NULL if no ID was set or for entity types that do not support renames.

string[] getCacheTagsToInvalidate()

Returns the cache tags that should be used to invalidate caches.

This will not return additional cache tags added through addCacheTags().

$this setOriginalId(int|string|null $id)

Sets the original ID.

Parameters

int|string|null $id

The new ID to set as original ID. If the entity supports renames, setting NULL will prevent an update from being considered a rename.

Return Value

$this

array toArray()

Gets an array of all property values.

Return Value

array

An array of property values, keyed by property name.

ComplexDataInterface getTypedData()

Gets a typed data object for this entity object.

The returned typed data object wraps this entity and allows dealing with entities based on the generic typed data API.

Return Value

ComplexDataInterface

The typed data object for this entity.

See also

TypedDataInterface

string getConfigDependencyKey()

Gets the key that is used to store configuration dependencies.

Return Value

string

The key to be used in configuration dependencies when storing dependencies on entities of this type.

See also

EntityTypeInterface::getConfigDependencyKey

string getConfigDependencyName()

Gets the configuration dependency name.

Configuration entities can depend on content and configuration entities. They store an array of content and config dependency names in their "dependencies" key.

Return Value

string

The configuration dependency name.

See also

ConfigDependencyManager

string getConfigTarget()

Gets the configuration target identifier for the entity.

Used to supply the correct format for storing a reference targeting this entity in configuration.

Return Value

string

The configuration target identifier.

$this setThirdPartySetting(string $module, string $key, mixed $value)

Sets the value of a third-party setting.

Parameters

string $module

The module providing the third-party setting.

string $key

The setting name.

mixed $value

The setting value.

Return Value

$this

mixed getThirdPartySetting(string $module, string $key, mixed $default = NULL)

Gets the value of a third-party setting.

Parameters

string $module

The module providing the third-party setting.

string $key

The setting name.

mixed $default

The default value

Return Value

mixed

The value.

array getThirdPartySettings(string $module)

Gets all third-party settings of a given module.

Parameters

string $module

The module providing the third-party settings.

Return Value

array

An array of key-value pairs.

mixed unsetThirdPartySetting(string $module, string $key)

Unsets a third-party setting.

Parameters

string $module

The module providing the third-party setting.

string $key

The setting name.

Return Value

mixed

The value.

array getThirdPartyProviders()

Gets the list of third parties that store information.

Return Value

array

The list of third parties.

$this setSyncing(bool $status)

Sets the status of the synchronization flag.

Parameters

bool $status

The status of the synchronization flag.

Return Value

$this

bool isSyncing()

Returns whether this entity is being changed as part of a synchronization.

If you are writing code that responds to a change in this entity (insert, update, delete, presave, etc.), and your code would result in a change to this entity itself, a configuration change (whether related to this entity, another entity, or non-entity configuration), you need to check and see if this entity change is part of a synchronization process, and skip executing your code if that is the case.

For example, \Drupal\node\Entity\NodeType::postSave() adds the default body field to newly created node type configuration entities, which is a configuration change. You would not want this code to run during an import, because imported entities were already given the body field when they were originally created, and the imported configuration includes all of their currently-configured fields. On the other hand, \Drupal\field\Entity\FieldStorageConfig::preSave() and the methods it calls make sure that the storage tables are created or updated for the field storage configuration entity, which is not a configuration change, and it must be done whether due to an import or not. So, the first method should check $entity->isSyncing() and skip executing if it returns TRUE, and the second should not perform this check.

Return Value

bool

TRUE if the configuration entity is being created, updated, or deleted through a synchronization process.

$this enable()

Enables the configuration entity.

Return Value

$this

$this disable()

Disables the configuration entity.

Return Value

$this

$this setStatus(bool $status)

Sets the status of the configuration entity.

Parameters

bool $status

The status of the configuration entity.

Return Value

$this

bool status()

Returns whether the configuration entity is enabled.

Status implementations for configuration entities should follow these general rules:

  • Status does not affect the loading of entities. I.e. Disabling configuration entities should only have UI/access implications.
  • It should only take effect when a 'status' key is explicitly declared in the entity_keys info of a configuration entity's annotation data.
  • Each entity implementation (entity/controller) is responsible for checking and managing the status.

Return Value

bool

Whether the entity is enabled or not.

bool isUninstalling()

Returns whether this entity is being changed during the uninstall process.

If you are writing code that responds to a change in this entity (insert, update, delete, presave, etc.), and your code would result in a configuration change (whether related to this configuration entity, another configuration entity, or non-entity configuration) or your code would result in a change to this entity itself, you need to check and see if this entity change is part of an uninstall process, and skip executing your code if that is the case.

For example, \Drupal\language\Entity\ConfigurableLanguage::preDelete() prevents the API from deleting the default language. However during an uninstall of the language module it is expected that the default language should be deleted.

Return Value

bool

mixed get(string $property_name)

Returns the value of a property.

Parameters

string $property_name

The name of the property that should be returned.

Return Value

mixed

The property if it exists, or NULL otherwise.

$this set(string $property_name, mixed $value)

Sets the value of a property.

Parameters

string $property_name

The name of the property that should be set.

mixed $value

The value the property should be set to.

Return Value

$this

$this calculateDependencies()

Calculates dependencies and stores them in the dependency property.

Return Value

$this

See also

ConfigDependencyManager

bool onDependencyRemoval(array $dependencies)

Informs the entity that entities it depends on will be deleted.

This method allows configuration entities to remove dependencies instead of being deleted themselves. Configuration entities can use this method to avoid being unnecessarily deleted during an extension uninstallation. For example, entity displays remove references to widgets and formatters if the plugin that supplies them depends on a module that is being uninstalled.

If this method returns TRUE then the entity needs to be re-saved by the caller for the changes to take effect. Implementations should not save the entity.

Parameters

array $dependencies

An array of dependencies that will be deleted keyed by dependency type. Dependency types are, for example, entity, module and theme.

Return Value

bool

TRUE if the entity has been changed as a result, FALSE if not.

See also

ConfigDependencyManager
\Drupal\Core\Config\ConfigEntityBase::preDelete()
ConfigManager::uninstall
EntityDisplayBase::onDependencyRemoval

array getDependencies()

Gets the configuration dependencies.

Return Value

array

An array of dependencies, keyed by $type.

See also

ConfigDependencyManager

bool isInstallable()

Checks whether this entity is installable.

For example, a default view might not be installable if the base table doesn't exist.

Return Value

bool

TRUE if the entity is installable, FALSE otherwise.

$this trustData()

Sets that the data should be trusted.

If the data is trusted then dependencies will not be calculated on save and schema will not be used to cast the values. Generally this is only used during module and theme installation. Once the config entity has been saved the data will no longer be marked as trusted. This is an optimization for creation of configuration during installation.

Return Value

$this

See also

ConfigInstaller::createConfiguration

bool hasTrustedData()

Gets whether on not the data is trusted.

Return Value

bool

TRUE if the configuration data is trusted, FALSE if not.

$this setLabel(string $label)

Sets the field definition label.

Parameters

string $label

The label to set.

Return Value

$this

$this setDescription(string $description)

Sets a human readable description.

Descriptions are usually used on user interfaces where the data is edited or displayed.

Parameters

string $description

The description for this field.

Return Value

$this

$this setTranslatable(bool $translatable)

Sets whether the field is translatable.

Parameters

bool $translatable

Whether the field is translatable.

Return Value

$this

$this setSettings(array $settings)

Sets field settings.

Note that the method does not unset existing settings not specified in the incoming $settings array.

For example:

Parameters

array $settings

The array of field settings.

Return Value

$this

$this setSetting(string $setting_name, mixed $value)

Sets the value for a field setting by name.

Parameters

string $setting_name

The name of the setting.

mixed $value

The value of the setting.

Return Value

$this

$this setRequired(bool $required)

Sets whether the field can be empty.

If a field is required, an entity needs to have at least a valid, non-empty item in that field's FieldItemList in order to pass validation.

An item is considered empty if its isEmpty() method returns TRUE. Typically, that is if at least one of its required properties is empty.

Parameters

bool $required

TRUE if the field is required. FALSE otherwise.

Return Value

$this

The current object, for a fluent interface.

$this setDefaultValue(mixed $value)

Sets a default value.

Note that if a default value callback is set, it will take precedence over any value set here.

Parameters

mixed $value

The default value for the field. This can be either:

  • a literal, in which case it will be assigned to the first property of the first item.
  • a numerically indexed array of items, each item being a property/value array.
  • a non-numerically indexed array, in which case the array is assumed to be a property/value array and used as the first item
  • NULL or array() for no default value.

Return Value

$this

$this setDefaultValueCallback(string|null $callback)

Sets a custom default value callback.

If set, the callback overrides any set default value.

Parameters

string|null $callback

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\FieldableEntityInterface $entity The entity being created.
  • \Drupal\Core\Field\FieldDefinitionInterface $definition The field definition. It should return the default value in the format accepted by the setDefaultValue() method.

Return Value

$this

FieldConfigInterface setPropertyConstraints(string $name, array $constraints)

Sets constraints for a given field item property.

Note: this overwrites any existing property constraints. If you need to add to the existing constraints, use \Drupal\Core\Field\FieldConfigInterface::addPropertyConstraints()

Note that constraints added via this method are not stored in configuration and as such need to be added at runtime using hook_entity_bundle_field_info_alter().

Parameters

string $name

The name of the property to set constraints for.

array $constraints

The constraints to set.

Return Value

FieldConfigInterface

The object itself for chaining.

See also

hook_entity_bundle_field_info_alter()

FieldConfigInterface addPropertyConstraints(string $name, array $constraints)

Adds constraints for a given field item property.

Adds a constraint to a property of a field item. e.g.

Parameters

string $name

The name of the property to set constraints for.

array $constraints

The constraints to set.

Return Value

FieldConfigInterface

The object itself for chaining.

See also

FieldConfigInterface::addConstraint
hook_entity_bundle_field_info_alter()

$this setConstraints(array $constraints)

Sets the array of validation constraints for the FieldItemList.

NOTE: This will overwrite any previously set constraints. In most cases FieldConfigInterface::addConstraint() should be used instead.

Note that constraints added via this method are not stored in configuration and as such need to be added at runtime using hook_entity_bundle_field_info_alter().

Parameters

array $constraints

The array of constraints. See \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details.

Return Value

$this

See also

DataDefinition::addConstraint
DataDefinition::getConstraints
FieldItemList
hook_entity_bundle_field_info_alter()