class EntityManager implements EntityManagerInterface, ContainerAwareInterface (View source)

Provides a wrapper around many other services relating to entities.

Deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. We cannot use the deprecated PHPDoc tag because this service class is still used in legacy code paths. Symfony would fail test cases with deprecation warnings.

Traits

ContainerAwareTrait

Methods

clearCachedDefinitions() deprecated

Clears static and persistent plugin definition caches.

mixed
getDefinition($entity_type_id, bool $exception_on_invalid = TRUE) deprecated

Gets a specific plugin definition.

bool
hasHandler(string $entity_type_id, string $handler_type) deprecated

Checks whether a certain entity type has a certain handler.

getStorage(string $entity_type_id) deprecated

Creates a new storage instance.

getListBuilder(string $entity_type_id) deprecated

Creates a new entity list builder.

getFormObject(string $entity_type_id, string $operation) deprecated

Creates a new form instance.

getRouteProviders(string $entity_type_id) deprecated

Gets all route provider instances.

getViewBuilder(string $entity_type_id) deprecated

Creates a new view builder instance.

getAccessControlHandler(string $entity_type_id) deprecated

Creates a new access control handler instance.

object
getHandler(string $entity_type_id, string $handler_type) deprecated

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

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

Creates new handler instance.

getBaseFieldDefinitions(string $entity_type_id) deprecated

Gets the base field definitions for a content entity type.

getFieldDefinitions(string $entity_type_id, string $bundle) deprecated

Gets the field definitions for a specific bundle.

getFieldStorageDefinitions(string $entity_type_id) deprecated

Gets the field storage definitions for a content entity type.

getActiveFieldStorageDefinitions($entity_type_id) deprecated

{@inheritdoc}

$this
setFieldMap(array $field_map) deprecated

Sets a lightweight map of fields across bundles.

array
getFieldMap() deprecated

Gets a lightweight map of fields across bundles.

array
getFieldMapByFieldType(string $field_type) deprecated

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

onFieldDefinitionCreate(FieldDefinitionInterface $field_definition) deprecated

Reacts to the creation of a field.

onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original) deprecated

Reacts to the update of a field.

onFieldDefinitionDelete(FieldDefinitionInterface $field_definition) deprecated

Reacts to the deletion of a field.

clearCachedFieldDefinitions() deprecated

Clears static and persistent field definition caches.

clearCachedBundles() deprecated

Clears static and persistent bundles.

array
getBundleInfo(string $entity_type_id) deprecated

Gets the bundle info of an entity type.

array
getAllBundleInfo() deprecated

Get the bundle info of all entity types.

array
getExtraFields(string $entity_type_id, string $bundle) deprecated

Gets the "extra fields" for a bundle.

array
getEntityTypeLabels(bool $group = FALSE) deprecated

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

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

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

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

Retrieves the active entity variant matching the specified context.

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

Retrieves the active entity variants matching the specified context.

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

Retrieves the canonical entity variant matching the specified context.

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

Retrieves the canonical entity variants matching the specified context.

array
getAllViewModes() deprecated

Gets the entity view mode info for all entity types.

array
getViewModes(string $entity_type_id) deprecated

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

array
getAllFormModes() deprecated

Gets the entity form mode info for all entity types.

array
getFormModes(string $entity_type_id) deprecated

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

array
getViewModeOptions(string $entity_type_id) deprecated

Gets an array of view mode options.

array
getFormModeOptions(string $entity_type_id) deprecated

Gets an array of form mode options.

array
getViewModeOptionsByBundle(string $entity_type_id, string $bundle) deprecated

Returns an array of enabled view mode options by bundle.

array
getFormModeOptionsByBundle(string $entity_type_id, string $bundle) deprecated

Returns an array of enabled form mode options by bundle.

$this
clearDisplayModeInfo() deprecated

Clears the gathered display mode info.

loadEntityByUuid(string $entity_type_id, string $uuid) deprecated

Loads an entity by UUID.

loadEntityByConfigTarget(string $entity_type_id, string $target) deprecated

Loads an entity by the config target identifier.

string
getEntityTypeFromClass(string $class_name) deprecated

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

onEntityTypeCreate(EntityTypeInterface $entity_type)

Reacts to the creation of the entity type.

onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions) deprecated

Reacts to the creation of the fieldable entity type.

onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) deprecated

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) deprecated

Reacts to the update of a fieldable entity type.

onEntityTypeDelete(EntityTypeInterface $entity_type) deprecated

Reacts to the deletion of the entity type.

onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) deprecated

Reacts to the creation of a field storage definition.

onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) deprecated

Reacts to the update of a field storage definition.

onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) deprecated

Reacts to the deletion of a field storage definition.

onBundleCreate(string $bundle, string $entity_type_id) deprecated

Reacts to a bundle being created.

onBundleDelete(string $bundle, string $entity_type_id) deprecated

Reacts to a bundle being deleted.

getLastInstalledDefinition($entity_type_id) deprecated

No description

useCaches(bool $use_caches = FALSE) deprecated

Disable the use of caches.

getLastInstalledFieldStorageDefinitions($entity_type_id) deprecated

No description

array
getDefinitions() deprecated

Gets the definition of all plugins for this type.

bool
hasDefinition(string $plugin_id) deprecated

Indicates if a specific plugin definition exists.

getActiveDefinition($entity_type_id) deprecated

{@inheritdoc}

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

Creates a pre-configured instance of a plugin.

object|false
getInstance(array $options) deprecated

Gets a preconfigured instance of a plugin.

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

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) deprecated

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

Details

clearCachedDefinitions() deprecated

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

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!

mixed getDefinition($entity_type_id, bool $exception_on_invalid = TRUE) deprecated

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

Gets a specific plugin definition.

Parameters

$entity_type_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

See also

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

bool hasHandler(string $entity_type_id, string $handler_type) deprecated

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

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.

See also

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

EntityStorageInterface getStorage(string $entity_type_id) deprecated

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

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

See also

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

EntityListBuilderInterface getListBuilder(string $entity_type_id) deprecated

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

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.

See also

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

EntityFormInterface getFormObject(string $entity_type_id, string $operation) deprecated

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

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.

See also

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

EntityRouteProviderInterface[] getRouteProviders(string $entity_type_id) deprecated

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

Gets all route provider instances.

Parameters

string $entity_type_id

The entity type ID for the route providers.

Return Value

EntityRouteProviderInterface[]

See also

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

EntityViewBuilderInterface getViewBuilder(string $entity_type_id) deprecated

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

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.

See also

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

EntityAccessControlHandlerInterface getAccessControlHandler(string $entity_type_id) deprecated

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

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.

See also

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

object getHandler(string $entity_type_id, string $handler_type) deprecated

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

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

See also

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

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

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

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.

See also

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

FieldDefinitionInterface[] getBaseFieldDefinitions(string $entity_type_id) deprecated

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

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

See also

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

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

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

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.

See also

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

FieldStorageDefinitionInterface[] getFieldStorageDefinitions(string $entity_type_id) deprecated

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

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

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

getActiveFieldStorageDefinitions($entity_type_id) deprecated

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

{@inheritdoc}

Parameters

$entity_type_id

See also

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

$this setFieldMap(array $field_map) deprecated

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

Sets a lightweight map of fields across bundles.

Parameters

array $field_map

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

Return Value

$this

See also

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

array getFieldMap() deprecated

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

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.

See also

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

array getFieldMapByFieldType(string $field_type) deprecated

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

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.

See also

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

onFieldDefinitionCreate(FieldDefinitionInterface $field_definition) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionCreate() instead.

Reacts to the creation of a field.

Parameters

FieldDefinitionInterface $field_definition

The field definition created.

See also

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

onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionUpdate() instead.

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.

See also

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

onFieldDefinitionDelete(FieldDefinitionInterface $field_definition) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionDelete() instead.

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.

See also

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

clearCachedFieldDefinitions() deprecated

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

Clears static and persistent field definition caches.

clearCachedBundles() deprecated

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

Clears static and persistent bundles.

array getBundleInfo(string $entity_type_id) deprecated

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

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.

See also

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

array getAllBundleInfo() deprecated

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

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.

See also

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

array getExtraFields(string $entity_type_id, string $bundle) deprecated

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

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.

See also

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

array getEntityTypeLabels(bool $group = FALSE) deprecated

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

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.

See also

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

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

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

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

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

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

deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityRepositoryInterface::getActive() instead.

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.

See also

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

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

deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityRepositoryInterface::getActiveMultiple() instead.

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

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

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

deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityRepositoryInterface::getCanonical() instead.

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.

See also

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

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

deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityRepositoryInterface::getCanonicalMultiple() instead.

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

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

array getAllViewModes() deprecated

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

Gets the entity view mode info for all entity types.

Return Value

array

The view mode info for all entity types.

See also

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

array getViewModes(string $entity_type_id) deprecated

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

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.

See also

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

array getAllFormModes() deprecated

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

Gets the entity form mode info for all entity types.

Return Value

array

The form mode info for all entity types.

See also

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

array getFormModes(string $entity_type_id) deprecated

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

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.

See also

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

array getViewModeOptions(string $entity_type_id) deprecated

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

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.

See also

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

array getFormModeOptions(string $entity_type_id) deprecated

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

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.

See also

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

array getViewModeOptionsByBundle(string $entity_type_id, string $bundle) deprecated

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

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.

See also

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

array getFormModeOptionsByBundle(string $entity_type_id, string $bundle) deprecated

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

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.

See also

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

$this clearDisplayModeInfo() deprecated

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

Clears the gathered display mode info.

Return Value

$this

See also

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

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

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

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

See also

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

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

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

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

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

string getEntityTypeFromClass(string $class_name) deprecated

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

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

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

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) deprecated

deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityTypeListenerInterface::onFieldableEntityTypeCreate() instead.

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.

See also

https://www.drupal.org/project/drupal/issues/3043455

onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) deprecated

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

Reacts to the update of the entity type.

Parameters

EntityTypeInterface $entity_type

The updated entity type definition.

EntityTypeInterface $original

The original entity type definition.

See also

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

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

deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityTypeListenerInterface::onFieldableEntityTypeUpdate() instead.

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.

See also

https://www.drupal.org/project/drupal/issues/2984782

onEntityTypeDelete(EntityTypeInterface $entity_type) deprecated

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

Reacts to the deletion of the entity type.

Parameters

EntityTypeInterface $entity_type

The entity type being deleted.

See also

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

onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Field\FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionCreate() instead.

Reacts to the creation of a field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The definition being created.

See also

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

onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Field\FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionUpdate() instead.

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

See also

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

onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Field\FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionDelete() instead.

Reacts to the deletion of a field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field being deleted.

See also

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

onBundleCreate(string $bundle, string $entity_type_id) deprecated

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

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'.

See also

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

onBundleDelete(string $bundle, string $entity_type_id) deprecated

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

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'.

See also

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

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

useCaches(bool $use_caches = FALSE) deprecated

deprecated EntityManagerInterface::useCaches() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeManagerInterface::useCaches() and/or Drupal\Core\Entity\EntityFieldManagerInterface::useCaches() instead.

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.

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

array getDefinitions() deprecated

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

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

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

bool hasDefinition(string $plugin_id) deprecated

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

Indicates if a specific plugin definition exists.

Parameters

string $plugin_id

A plugin ID.

Return Value

bool

TRUE if the definition exists, FALSE otherwise.

See also

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

getActiveDefinition($entity_type_id) deprecated

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

{@inheritdoc}

Parameters

$entity_type_id

See also

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

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

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

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

See also

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

object|false getInstance(array $options) deprecated

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

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.

See also

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

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

deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityTypeManagerInterface::getViewDisplay() instead.

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) deprecated

deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityTypeManagerInterface::getFormwDisplay() instead.

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.