interface EntityManagerInterface implements EntityTypeListenerInterface, EntityBundleListenerInterface, FieldStorageDefinitionListenerInterface, FieldDefinitionListenerInterface, EntityTypeManagerInterface, EntityTypeRepositoryInterface, EntityTypeBundleInfoInterface, EntityDisplayRepositoryInterface, EntityFieldManagerInterface, EntityRepositoryInterface (View source)

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.

Provides an interface for entity type managers.

Methods

onEntityTypeCreate(EntityTypeInterface $entity_type)

Reacts to the creation of the entity type.

onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions)

Reacts to the creation of the fieldable entity type.

onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Reacts to the update of the entity type.

onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox = NULL)

Reacts to the update of a fieldable entity type.

onEntityTypeDelete(EntityTypeInterface $entity_type)

Reacts to the deletion of the entity type.

onBundleCreate(string $bundle, string $entity_type_id)

Reacts to a bundle being created.

onBundleDelete(string $bundle, string $entity_type_id)

Reacts to a bundle being deleted.

onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition)

Reacts to the creation of a field storage definition.

onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Reacts to the update of a field storage definition.

onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition)

Reacts to the deletion of a field storage definition.

onFieldDefinitionCreate(FieldDefinitionInterface $field_definition)

Reacts to the creation of a field.

onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original)

Reacts to the update of a field.

onFieldDefinitionDelete(FieldDefinitionInterface $field_definition)

Reacts to the deletion of a field.

mixed
getDefinition(string $plugin_id, bool $exception_on_invalid = TRUE)

Gets a specific plugin definition.

array
getDefinitions()

Gets the definition of all plugins for this type.

bool
hasDefinition(string $plugin_id)

Indicates if a specific plugin definition exists.

object
createInstance(string $plugin_id, array $configuration = [])

Creates a pre-configured instance of a plugin.

object|false
getInstance(array $options)

Gets a preconfigured instance of a plugin.

clearCachedDefinitions()

Clears static and persistent plugin definition caches.

useCaches(bool $use_caches = FALSE)

Disable the use of caches.

getAccessControlHandler(string $entity_type_id)

Creates a new access control handler instance.

getStorage(string $entity_type_id)

Creates a new storage instance.

getViewBuilder(string $entity_type_id)

Creates a new view builder instance.

getListBuilder(string $entity_type_id)

Creates a new entity list builder.

getFormObject(string $entity_type_id, string $operation)

Creates a new form instance.

getRouteProviders(string $entity_type_id)

Gets all route provider instances.

bool
hasHandler(string $entity_type_id, string $handler_type)

Checks whether a certain entity type has a certain handler.

object
getHandler(string $entity_type_id, string $handler_type)

Returns a handler instance for the given entity type and handler.

object
createHandlerInstance(mixed $class, EntityTypeInterface $definition = NULL)

Creates new handler instance.

array
getEntityTypeLabels(bool $group = FALSE)

Builds a list of entity type labels suitable for a Form API options list.

string
getEntityTypeFromClass(string $class_name)

Gets the entity type ID based on the class that is called on.

array
getAllBundleInfo()

Get the bundle info of all entity types.

array
getBundleInfo(string $entity_type_id)

Gets the bundle info of an entity type.

clearCachedBundles()

Clears static and persistent bundles.

array
getAllViewModes()

Gets the entity view mode info for all entity types.

array
getViewModes(string $entity_type_id)

Gets the entity view mode info for a specific entity type.

array
getAllFormModes()

Gets the entity form mode info for all entity types.

array
getFormModes(string $entity_type_id)

Gets the entity form mode info for a specific entity type.

array
getViewModeOptions(string $entity_type_id)

Gets an array of view mode options.

array
getFormModeOptions(string $entity_type_id)

Gets an array of form mode options.

array
getViewModeOptionsByBundle(string $entity_type_id, string $bundle)

Returns an array of enabled view mode options by bundle.

array
getFormModeOptionsByBundle(string $entity_type_id, string $bundle)

Returns an array of enabled form mode options by bundle.

$this
clearDisplayModeInfo()

Clears the gathered display mode info.

getViewDisplay(string $entity_type, string $bundle, string $view_mode = self::DEFAULT_DISPLAY_MODE)

Returns the entity view display associated with a bundle and view mode.

getFormDisplay(string $entity_type, string $bundle, string $form_mode = self::DEFAULT_DISPLAY_MODE)

Returns the entity form display associated with a bundle and form mode.

getBaseFieldDefinitions(string $entity_type_id)

Gets the base field definitions for a content entity type.

getFieldDefinitions(string $entity_type_id, string $bundle)

Gets the field definitions for a specific bundle.

getFieldStorageDefinitions(string $entity_type_id)

Gets the field storage definitions for a content entity type.

array
getFieldMap()

Gets a lightweight map of fields across bundles.

$this
setFieldMap(array $field_map)

Sets a lightweight map of fields across bundles.

array
getFieldMapByFieldType(string $field_type)

Gets a lightweight map of fields across bundles filtered by field type.

clearCachedFieldDefinitions()

Clears static and persistent field definition caches.

array
getExtraFields(string $entity_type_id, string $bundle)

Gets the "extra fields" for a bundle.

loadEntityByUuid(string $entity_type_id, string $uuid)

Loads an entity by UUID.

loadEntityByConfigTarget(string $entity_type_id, string $target)

Loads an entity by the config target identifier.

getTranslationFromContext(EntityInterface $entity, string $langcode = NULL, array $context = [])

Gets the entity translation to be used in the given context.

getActive(string $entity_type_id, int|string $entity_id, array $contexts = NULL)

Retrieves the active entity variant matching the specified context.

getActiveMultiple(string $entity_type_id, array $entity_ids, array $contexts = NULL)

Retrieves the active entity variants matching the specified context.

getCanonical(string $entity_type_id, int|string $entity_id, array $contexts = NULL)

Retrieves the canonical entity variant matching the specified context.

getCanonicalMultiple(string $entity_type_id, array $entity_ids, array $contexts = NULL)

Retrieves the canonical entity variants matching the specified context.

getLastInstalledDefinition($entity_type_id) deprecated

No description

getLastInstalledFieldStorageDefinitions($entity_type_id) deprecated

No description

Details

onEntityTypeCreate(EntityTypeInterface $entity_type)

Reacts to the creation of the entity type.

Parameters

EntityTypeInterface $entity_type

The entity type being created.

onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions)

Reacts to the creation of the fieldable entity type.

Parameters

EntityTypeInterface $entity_type

The entity type being created.

array $field_storage_definitions

The entity type's field storage definitions.

onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Reacts to the update of the entity type.

Parameters

EntityTypeInterface $entity_type

The updated entity type definition.

EntityTypeInterface $original

The original entity type definition.

onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox = NULL)

Reacts to the update of a fieldable entity type.

Parameters

EntityTypeInterface $entity_type

The updated entity type definition.

EntityTypeInterface $original

The original entity type definition.

array $field_storage_definitions

The updated field storage definitions, including possibly new ones.

array $original_field_storage_definitions

The original field storage definitions.

array $sandbox

(optional) A sandbox array provided by a hook_update_N() implementation or a Batch API callback. If the entity schema update requires a data migration, this parameter is mandatory. Defaults to NULL.

onEntityTypeDelete(EntityTypeInterface $entity_type)

Reacts to the deletion of the entity type.

Parameters

EntityTypeInterface $entity_type

The entity type being deleted.

onBundleCreate(string $bundle, string $entity_type_id)

Reacts to a bundle being created.

Parameters

string $bundle

The name of the bundle created.

string $entity_type_id

The entity type to which the bundle is bound; e.g. 'node' or 'user'.

onBundleDelete(string $bundle, string $entity_type_id)

Reacts to a bundle being deleted.

This method runs before fields are deleted.

Parameters

string $bundle

The name of the bundle being deleted.

string $entity_type_id

The entity type to which the bundle is bound; e.g. 'node' or 'user'.

onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition)

Reacts to the creation of a field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The definition being created.

onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Reacts to the update of a field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field being updated.

FieldStorageDefinitionInterface $original

The original storage definition; i.e., the definition before the update.

Exceptions

FieldStorageDefinitionUpdateForbiddenException

onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition)

Reacts to the deletion of a field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field being deleted.

onFieldDefinitionCreate(FieldDefinitionInterface $field_definition)

Reacts to the creation of a field.

Parameters

FieldDefinitionInterface $field_definition

The field definition created.

onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original)

Reacts to the update of a field.

Parameters

FieldDefinitionInterface $field_definition

The field definition being updated.

FieldDefinitionInterface $original

The original field definition; i.e., the definition before the update.

onFieldDefinitionDelete(FieldDefinitionInterface $field_definition)

Reacts to the deletion of a field.

Stored values should not be wiped at once, but marked as 'deleted' so that they can go through a proper purge process later on.

Parameters

FieldDefinitionInterface $field_definition

The field definition being deleted.

mixed getDefinition(string $plugin_id, bool $exception_on_invalid = TRUE)

Gets a specific plugin definition.

Parameters

string $plugin_id

A plugin id.

bool $exception_on_invalid

(optional) If TRUE, an invalid plugin ID will throw an exception.

Return Value

mixed

A plugin definition, or NULL if the plugin ID is invalid and $exception_on_invalid is FALSE.

Exceptions

PluginNotFoundException

array getDefinitions()

Gets the definition of all plugins for this type.

Return Value

array

An array of plugin definitions (empty array if no definitions were found). Keys are plugin IDs.

See also

FilteredPluginManagerInterface::getFilteredDefinitions

bool hasDefinition(string $plugin_id)

Indicates if a specific plugin definition exists.

Parameters

string $plugin_id

A plugin ID.

Return Value

bool

TRUE if the definition exists, FALSE otherwise.

object createInstance(string $plugin_id, array $configuration = [])

Creates a pre-configured instance of a plugin.

Parameters

string $plugin_id

The ID of the plugin being instantiated.

array $configuration

An array of configuration relevant to the plugin instance.

Return Value

object

A fully configured plugin instance.

Exceptions

PluginException

object|false getInstance(array $options)

Gets a preconfigured instance of a plugin.

Parameters

array $options

An array of options that can be used to determine a suitable plugin to instantiate and how to configure it.

Return Value

object|false

A fully configured plugin instance. The interface of the plugin instance will depend on the plugin type. If no instance can be retrieved, FALSE will be returned.

clearCachedDefinitions()

Clears static and persistent plugin definition caches.

Don't resort to calling \Drupal::cache()->delete() and friends to make Drupal detect new or updated plugin definitions. Always use this method on the appropriate plugin type's plugin manager!

useCaches(bool $use_caches = FALSE)

Disable the use of caches.

Can be used to ensure that uncached plugin definitions are returned, without invalidating all cached information.

This will also remove all local/static caches.

Parameters

bool $use_caches

FALSE to not use any caches.

EntityAccessControlHandlerInterface getAccessControlHandler(string $entity_type_id)

Creates a new access control handler instance.

Parameters

string $entity_type_id

The entity type ID for this access control handler.

Return Value

EntityAccessControlHandlerInterface

A access control handler instance.

EntityStorageInterface getStorage(string $entity_type_id)

Creates a new storage instance.

Parameters

string $entity_type_id

The entity type ID for this storage.

Return Value

EntityStorageInterface

A storage instance.

Exceptions

PluginNotFoundException
InvalidPluginDefinitionException

EntityViewBuilderInterface getViewBuilder(string $entity_type_id)

Creates a new view builder instance.

Parameters

string $entity_type_id

The entity type ID for this view builder.

Return Value

EntityViewBuilderInterface

A view builder instance.

EntityListBuilderInterface getListBuilder(string $entity_type_id)

Creates a new entity list builder.

Parameters

string $entity_type_id

The entity type ID for this list builder.

Return Value

EntityListBuilderInterface

An entity list builder instance.

EntityFormInterface getFormObject(string $entity_type_id, string $operation)

Creates a new form instance.

Parameters

string $entity_type_id

The entity type ID for this form.

string $operation

The name of the operation to use, e.g., 'default'.

Return Value

EntityFormInterface

A form instance.

EntityRouteProviderInterface[] getRouteProviders(string $entity_type_id)

Gets all route provider instances.

Parameters

string $entity_type_id

The entity type ID for the route providers.

Return Value

EntityRouteProviderInterface[]

bool hasHandler(string $entity_type_id, string $handler_type)

Checks whether a certain entity type has a certain handler.

Parameters

string $entity_type_id

The ID of the entity type.

string $handler_type

The name of the handler.

Return Value

bool

Returns TRUE if the entity type has the handler, else FALSE.

object getHandler(string $entity_type_id, string $handler_type)

Returns a handler instance for the given entity type and handler.

Entity handlers are instantiated once per entity type and then cached in the entity type manager, and so subsequent calls to getHandler() for a particular entity type and handler type will return the same object. This means that properties on a handler may be used as a static cache, although as the handler is common to all entities of the same type, any data that is per-entity should be keyed by the entity ID.

Parameters

string $entity_type_id

The entity type ID for this handler.

string $handler_type

The handler type to create an instance for.

Return Value

object

A handler instance.

Exceptions

InvalidPluginDefinitionException

object createHandlerInstance(mixed $class, EntityTypeInterface $definition = NULL)

Creates new handler instance.

Usually \Drupal\Core\Entity\EntityManagerInterface::getHandler() is preferred since that method has additional checking that the class exists and has static caches.

Parameters

mixed $class

The handler class to instantiate.

EntityTypeInterface $definition

The entity type definition.

Return Value

object

A handler instance.

array getEntityTypeLabels(bool $group = FALSE)

Builds a list of entity type labels suitable for a Form API options list.

Parameters

bool $group

(optional) Whether to group entity types by plugin group (e.g. 'content', 'config'). Defaults to FALSE.

Return Value

array

An array of entity type labels, keyed by entity type name.

string getEntityTypeFromClass(string $class_name)

Gets the entity type ID based on the class that is called on.

Compares the class this is called on against the known entity classes and returns the entity type ID of a direct match or a subclass as fallback, to support entity type definitions that were altered.

Parameters

string $class_name

Class name to use for searching the entity type ID.

Return Value

string

The entity type ID.

Exceptions

AmbiguousEntityClassException
NoCorrespondingEntityClassException

See also

\Drupal\Core\Entity\Entity::load()
\Drupal\Core\Entity\Entity::loadMultiple()

array getAllBundleInfo()

Get the bundle info of all entity types.

Return Value

array

An array of bundle information where the outer array is keyed by entity type. The next level is keyed by the bundle name. The inner arrays are associative arrays of bundle information, such as the label for the bundle.

array getBundleInfo(string $entity_type_id)

Gets the bundle info of an entity type.

Parameters

string $entity_type_id

The entity type ID.

Return Value

array

An array of bundle information where the outer array is keyed by the bundle name, or the entity type name if the entity does not have bundles. The inner arrays are associative arrays of bundle information, such as the label for the bundle.

clearCachedBundles()

Clears static and persistent bundles.

array getAllViewModes()

Gets the entity view mode info for all entity types.

Return Value

array

The view mode info for all entity types.

array getViewModes(string $entity_type_id)

Gets the entity view mode info for a specific entity type.

Parameters

string $entity_type_id

The entity type whose view mode info should be returned.

Return Value

array

The view mode info for a specific entity type.

array getAllFormModes()

Gets the entity form mode info for all entity types.

Return Value

array

The form mode info for all entity types.

array getFormModes(string $entity_type_id)

Gets the entity form mode info for a specific entity type.

Parameters

string $entity_type_id

The entity type whose form mode info should be returned.

Return Value

array

The form mode info for a specific entity type.

array getViewModeOptions(string $entity_type_id)

Gets an array of view mode options.

Parameters

string $entity_type_id

The entity type whose view mode options should be returned.

Return Value

array

An array of view mode labels, keyed by the display mode ID.

array getFormModeOptions(string $entity_type_id)

Gets an array of form mode options.

Parameters

string $entity_type_id

The entity type whose form mode options should be returned.

Return Value

array

An array of form mode labels, keyed by the display mode ID.

array getViewModeOptionsByBundle(string $entity_type_id, string $bundle)

Returns an array of enabled view mode options by bundle.

Parameters

string $entity_type_id

The entity type whose view mode options should be returned.

string $bundle

The name of the bundle.

Return Value

array

An array of view mode labels, keyed by the display mode ID.

array getFormModeOptionsByBundle(string $entity_type_id, string $bundle)

Returns an array of enabled form mode options by bundle.

Parameters

string $entity_type_id

The entity type whose form mode options should be returned.

string $bundle

The name of the bundle.

Return Value

array

An array of form mode labels, keyed by the display mode ID.

$this clearDisplayModeInfo()

Clears the gathered display mode info.

Return Value

$this

EntityViewDisplayInterface getViewDisplay(string $entity_type, string $bundle, string $view_mode = self::DEFAULT_DISPLAY_MODE)

Returns the entity view display associated with a bundle and view mode.

Use this function when assigning suggested display options for a component in a given view mode. Note that they will only be actually used at render time if the view mode itself is configured to use dedicated display settings for the bundle; if not, the 'default' display is used instead.

The function reads the entity view display from the current configuration, or returns a ready-to-use empty one if configuration entry exists yet for this bundle and view mode. This streamlines manipulation of display objects by always returning a consistent object that reflects the current state of the configuration.

Example usage:

  • Set the 'body' field to be displayed and the 'field_image' field to be hidden on article nodes in the 'default' display.

Parameters

string $entity_type

The entity type.

string $bundle

The bundle.

string $view_mode

(optional) The view mode. Defaults to self::DEFAULT_DISPLAY_MODE.

Return Value

EntityViewDisplayInterface

The entity view display associated with the view mode.

EntityFormDisplayInterface getFormDisplay(string $entity_type, string $bundle, string $form_mode = self::DEFAULT_DISPLAY_MODE)

Returns the entity form display associated with a bundle and form mode.

The function reads the entity form display object from the current configuration, or returns a ready-to-use empty one if no configuration entry exists yet for this bundle and form mode. This streamlines manipulation of entity form displays by always returning a consistent object that reflects the current state of the configuration.

Example usage:

  • Set the 'body' field to be displayed with the 'text_textarea_with_summary' widget and the 'field_image' field to be hidden on article nodes in the 'default' form mode.

Parameters

string $entity_type

The entity type.

string $bundle

The bundle.

string $form_mode

(optional) The form mode. Defaults to self::DEFAULT_DISPLAY_MODE.

Return Value

EntityFormDisplayInterface

The entity form display associated with the given form mode.

See also

EntityStorageInterface::create
EntityStorageInterface::load

FieldDefinitionInterface[] getBaseFieldDefinitions(string $entity_type_id)

Gets the base field definitions for a content entity type.

Only fields that are not specific to a given bundle or set of bundles are returned. This excludes configurable fields, as they are always attached to a specific bundle.

Parameters

string $entity_type_id

The entity type ID. Only entity types that implement \Drupal\Core\Entity\FieldableEntityInterface are supported.

Return Value

FieldDefinitionInterface[]

The array of base field definitions for the entity type, keyed by field name.

Exceptions

LogicException

FieldDefinitionInterface[] getFieldDefinitions(string $entity_type_id, string $bundle)

Gets the field definitions for a specific bundle.

Parameters

string $entity_type_id

The entity type ID. Only entity types that implement \Drupal\Core\Entity\FieldableEntityInterface are supported.

string $bundle

The bundle.

Return Value

FieldDefinitionInterface[]

The array of field definitions for the bundle, keyed by field name.

FieldStorageDefinitionInterface[] getFieldStorageDefinitions(string $entity_type_id)

Gets the field storage definitions for a content entity type.

This returns all field storage definitions for base fields and bundle fields of an entity type. Note that field storage definitions of a base field equal the full base field definition (i.e. they implement FieldDefinitionInterface), while the storage definitions for bundle fields may implement FieldStorageDefinitionInterface only.

Parameters

string $entity_type_id

The entity type ID. Only content entities are supported.

Return Value

FieldStorageDefinitionInterface[]

The array of field storage definitions for the entity type, keyed by field name.

See also

FieldStorageDefinitionInterface

array getFieldMap()

Gets a lightweight map of fields across bundles.

Return Value

array

An array keyed by entity type. Each value is an array which keys are field names and value is an array with two entries:

  • type: The field type.
  • bundles: An associative array of the bundles in which the field appears, where the keys and values are both the bundle's machine name.

$this setFieldMap(array $field_map)

Sets a lightweight map of fields across bundles.

Parameters

array $field_map

See the return value of self::getFieldMap().

Return Value

$this

array getFieldMapByFieldType(string $field_type)

Gets a lightweight map of fields across bundles filtered by field type.

Parameters

string $field_type

The field type to filter by.

Return Value

array

An array keyed by entity type. Each value is an array which keys are field names and value is an array with two entries:

  • type: The field type.
  • bundles: An associative array of the bundles in which the field appears, where the keys and values are both the bundle's machine name.

clearCachedFieldDefinitions()

Clears static and persistent field definition caches.

array getExtraFields(string $entity_type_id, string $bundle)

Gets the "extra fields" for a bundle.

Parameters

string $entity_type_id

The entity type ID.

string $bundle

The bundle name.

Return Value

array

A nested array of 'pseudo-field' elements. Each list is nested within the following keys: entity type, bundle name, context (either 'form' or 'display'). The keys are the name of the elements as appearing in the renderable array (either the entity form or the displayed entity). The value is an associative array:

  • label: The human readable name of the element. Make sure you sanitize this appropriately.
  • description: A short description of the element contents.
  • weight: The default weight of the element.
  • visible: (optional) The default visibility of the element. Defaults to TRUE.
  • edit: (optional) String containing markup (normally a link) used as the element's 'edit' operation in the administration interface. Only for 'form' context.
  • delete: (optional) String containing markup (normally a link) used as the element's 'delete' operation in the administration interface. Only for 'form' context.

EntityInterface|null loadEntityByUuid(string $entity_type_id, string $uuid)

Loads an entity by UUID.

Note that some entity types may not support UUIDs.

Parameters

string $entity_type_id

The entity type ID to load from.

string $uuid

The UUID of the entity to load.

Return Value

EntityInterface|null

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

Exceptions

EntityStorageException

EntityInterface|null loadEntityByConfigTarget(string $entity_type_id, string $target)

Loads an entity by the config target identifier.

Parameters

string $entity_type_id

The entity type ID to load from.

string $target

The configuration target to load, as returned from \Drupal\Core\Entity\EntityInterface::getConfigTarget().

Return Value

EntityInterface|null

The entity object, or NULL if there is no entity with the given config target identifier.

Exceptions

EntityStorageException

See also

EntityInterface::getConfigTarget

EntityInterface getTranslationFromContext(EntityInterface $entity, string $langcode = NULL, array $context = [])

Gets the entity translation to be used in the given context.

This will check whether a translation for the desired language is available and if not, it will fall back to the most appropriate translation based on the provided context.

Parameters

EntityInterface $entity

The entity whose translation will be returned.

string $langcode

(optional) The language of the current context. Defaults to the current content language.

array $context

(optional) An associative array of arbitrary data that can be useful to determine the proper fallback sequence.

Return Value

EntityInterface

An entity object for the translated data.

See also

LanguageManagerInterface::getFallbackCandidates

EntityInterface|null getActive(string $entity_type_id, int|string $entity_id, array $contexts = NULL)

Retrieves the active entity variant matching the specified context.

If an entity type is revisionable and/or translatable, which entity variant should be handled depends on the context in which the manipulation happens. Based on the specified contextual information, revision and translation negotiation needs to be performed to return the active variant, that is the most up-to-date entity variant in the context scope. This may or may not be an entity variant intended for unprivileged user consumption, in fact it might be a work in progress containing yet to be published information. The active variant should always be retrieved when editing an entity, both in form and in REST workflows, or previewing the related changes.

The negotiation process will not perform any access check, so it is the responsibility of the caller to verify that the user manipulating the entity variant is actually allowed to do so.

Parameters

string $entity_type_id

The entity type identifier.

int|string $entity_id

An entity identifier.

array $contexts

(optional) An associative array of objects representing the contexts the entity will be edited in keyed by fully qualified context ID. Defaults to the currently available contexts.

Return Value

EntityInterface|null

An entity object variant or NULL if the entity does not exist.

EntityInterface getActiveMultiple(string $entity_type_id, array $entity_ids, array $contexts = NULL)

Retrieves the active entity variants matching the specified context.

Parameters

string $entity_type_id

The entity type identifier.

array $entity_ids

An array of entity identifiers.

array $contexts

(optional) An associative array of objects representing the contexts the entity will be edited in keyed by fully qualified context ID. Defaults to the currently available contexts.

Return Value

EntityInterface

An array of entity object variants keyed by entity ID.

See also

getActive()

EntityInterface|null getCanonical(string $entity_type_id, int|string $entity_id, array $contexts = NULL)

Retrieves the canonical entity variant matching the specified context.

If an entity type is revisionable and/or translatable, which entity variant should be handled depends on the context in which the manipulation happens. This will return the fittest entity variant intended for unprivileged user consumption matching the specified context. This is typically the variant that would be displayed on the entity's canonical route.

The negotiation process will not perform any access check, so it is the responsibility of the caller to verify that the user manipulating the entity variant is actually allowed to do so.

Parameters

string $entity_type_id

The entity type identifier.

int|string $entity_id

An entity identifier.

array $contexts

(optional) An associative array of objects representing the contexts the entity will be edited in keyed by fully qualified context ID. Defaults to the currently available contexts.

Return Value

EntityInterface|null

An entity object variant or NULL if the entity does not exist.

EntityInterface getCanonicalMultiple(string $entity_type_id, array $entity_ids, array $contexts = NULL)

Retrieves the canonical entity variants matching the specified context.

Parameters

string $entity_type_id

The entity type identifier.

array $entity_ids

An array of entity identifiers.

array $contexts

(optional) An associative array of objects representing the contexts the entity will be edited in keyed by fully qualified context ID. Defaults to the currently available contexts.

Return Value

EntityInterface

An array of entity object variants keyed by entity ID.

See also

getCanonical()

getLastInstalledDefinition($entity_type_id) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledDefinition() instead.

No description

Parameters

$entity_type_id

See also

https://www.drupal.org/node/2549139

getLastInstalledFieldStorageDefinitions($entity_type_id) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledFieldStorageDefinitions() instead.

No description

Parameters

$entity_type_id

See also

https://www.drupal.org/node/2549139