EntityManager
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
Methods
Gets a specific plugin definition.
Checks whether a certain entity type has a certain handler.
Creates a new access control handler instance.
Returns a handler instance for the given entity type and handler.
Creates new handler instance.
Gets the base field definitions for a content entity type.
Gets the field definitions for a specific bundle.
Gets the field storage definitions for a content entity type.
Gets a lightweight map of fields across bundles filtered by field type.
Reacts to the creation of a field.
Reacts to the update of a field.
Reacts to the deletion of a field.
Gets the "extra fields" for a bundle.
Builds a list of entity type labels suitable for a Form API options list.
Gets the entity translation to be used in the given context.
Retrieves the active entity variant matching the specified context.
Retrieves the active entity variants matching the specified context.
Retrieves the canonical entity variant matching the specified context.
Retrieves the canonical entity variants matching the specified context.
Gets the entity view mode info for a specific entity type.
Gets the entity form mode info for a specific entity type.
Returns an array of enabled view mode options by bundle.
Returns an array of enabled form mode options by bundle.
Loads an entity by the config target identifier.
Gets the entity type ID based on the class that is called on.
Reacts to the creation of the fieldable entity type.
Reacts to the update of the entity type.
Reacts to the update of a fieldable entity type.
Reacts to the deletion of the entity type.
Reacts to the creation of a field storage definition.
Reacts to the update of a field storage definition.
Reacts to the deletion of a field storage definition.
Creates a pre-configured instance of a plugin.
Returns the entity view display associated with a bundle and view mode.
Returns the entity form display associated with a bundle and form mode.
Details
clearCachedDefinitions()
deprecated
deprecated
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
Gets a specific plugin definition.
bool
hasHandler(string $entity_type_id, string $handler_type)
deprecated
deprecated
Checks whether a certain entity type has a certain handler.
EntityStorageInterface
getStorage(string $entity_type_id)
deprecated
deprecated
Creates a new storage instance.
EntityListBuilderInterface
getListBuilder(string $entity_type_id)
deprecated
deprecated
Creates a new entity list builder.
EntityFormInterface
getFormObject(string $entity_type_id, string $operation)
deprecated
deprecated
Creates a new form instance.
EntityRouteProviderInterface[]
getRouteProviders(string $entity_type_id)
deprecated
deprecated
Gets all route provider instances.
EntityViewBuilderInterface
getViewBuilder(string $entity_type_id)
deprecated
deprecated
Creates a new view builder instance.
EntityAccessControlHandlerInterface
getAccessControlHandler(string $entity_type_id)
deprecated
deprecated
Creates a new access control handler instance.
object
getHandler(string $entity_type_id, string $handler_type)
deprecated
deprecated
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.
object
createHandlerInstance(mixed $class, EntityTypeInterface $definition = NULL)
deprecated
deprecated
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.
FieldDefinitionInterface[]
getBaseFieldDefinitions(string $entity_type_id)
deprecated
deprecated
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.
FieldDefinitionInterface[]
getFieldDefinitions(string $entity_type_id, string $bundle)
deprecated
deprecated
Gets the field definitions for a specific bundle.
FieldStorageDefinitionInterface[]
getFieldStorageDefinitions(string $entity_type_id)
deprecated
deprecated
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.
getActiveFieldStorageDefinitions($entity_type_id)
deprecated
deprecated
{@inheritdoc}
$this
setFieldMap(array $field_map)
deprecated
deprecated
Sets a lightweight map of fields across bundles.
array
getFieldMap()
deprecated
deprecated
Gets a lightweight map of fields across bundles.
array
getFieldMapByFieldType(string $field_type)
deprecated
deprecated
Gets a lightweight map of fields across bundles filtered by field type.
onFieldDefinitionCreate(FieldDefinitionInterface $field_definition)
deprecated
deprecated
Reacts to the creation of a field.
onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original)
deprecated
deprecated
Reacts to the update of a field.
onFieldDefinitionDelete(FieldDefinitionInterface $field_definition)
deprecated
deprecated
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.
clearCachedFieldDefinitions()
deprecated
deprecated
Clears static and persistent field definition caches.
clearCachedBundles()
deprecated
deprecated
Clears static and persistent bundles.
array
getBundleInfo(string $entity_type_id)
deprecated
deprecated
Gets the bundle info of an entity type.
array
getAllBundleInfo()
deprecated
deprecated
Get the bundle info of all entity types.
array
getExtraFields(string $entity_type_id, string $bundle)
deprecated
deprecated
Gets the "extra fields" for a bundle.
array
getEntityTypeLabels(bool $group = FALSE)
deprecated
deprecated
Builds a list of entity type labels suitable for a Form API options list.
EntityInterface
getTranslationFromContext(EntityInterface $entity, string $langcode = NULL, array $context = [])
deprecated
deprecated
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.
EntityInterface|null
getActive(string $entity_type_id, int|string $entity_id, array $contexts = NULL)
deprecated
deprecated
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.
EntityInterface
getActiveMultiple(string $entity_type_id, array $entity_ids, array $contexts = NULL)
deprecated
deprecated
Retrieves the active entity variants matching the specified context.
EntityInterface|null
getCanonical(string $entity_type_id, int|string $entity_id, array $contexts = NULL)
deprecated
deprecated
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.
EntityInterface
getCanonicalMultiple(string $entity_type_id, array $entity_ids, array $contexts = NULL)
deprecated
deprecated
Retrieves the canonical entity variants matching the specified context.
array
getAllViewModes()
deprecated
deprecated
Gets the entity view mode info for all entity types.
array
getViewModes(string $entity_type_id)
deprecated
deprecated
Gets the entity view mode info for a specific entity type.
array
getAllFormModes()
deprecated
deprecated
Gets the entity form mode info for all entity types.
array
getFormModes(string $entity_type_id)
deprecated
deprecated
Gets the entity form mode info for a specific entity type.
array
getViewModeOptions(string $entity_type_id)
deprecated
deprecated
Gets an array of view mode options.
array
getFormModeOptions(string $entity_type_id)
deprecated
deprecated
Gets an array of form mode options.
array
getViewModeOptionsByBundle(string $entity_type_id, string $bundle)
deprecated
deprecated
Returns an array of enabled view mode options by bundle.
array
getFormModeOptionsByBundle(string $entity_type_id, string $bundle)
deprecated
deprecated
Returns an array of enabled form mode options by bundle.
$this
clearDisplayModeInfo()
deprecated
deprecated
Clears the gathered display mode info.
EntityInterface|null
loadEntityByUuid(string $entity_type_id, string $uuid)
deprecated
deprecated
Loads an entity by UUID.
Note that some entity types may not support UUIDs.
EntityInterface|null
loadEntityByConfigTarget(string $entity_type_id, string $target)
deprecated
deprecated
Loads an entity by the config target identifier.
string
getEntityTypeFromClass(string $class_name)
deprecated
deprecated
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.
onEntityTypeCreate(EntityTypeInterface $entity_type)
Reacts to the creation of the entity type.
onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions)
deprecated
deprecated
Reacts to the creation of the fieldable entity type.
onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)
deprecated
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
deprecated
Reacts to the update of a fieldable entity type.
onEntityTypeDelete(EntityTypeInterface $entity_type)
deprecated
deprecated
Reacts to the deletion of the entity type.
onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition)
deprecated
deprecated
Reacts to the creation of a field storage definition.
onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
deprecated
deprecated
Reacts to the update of a field storage definition.
onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition)
deprecated
deprecated
Reacts to the deletion of a field storage definition.
onBundleCreate(string $bundle, string $entity_type_id)
deprecated
deprecated
Reacts to a bundle being created.
onBundleDelete(string $bundle, string $entity_type_id)
deprecated
deprecated
Reacts to a bundle being deleted.
This method runs before fields are deleted.
getLastInstalledDefinition($entity_type_id)
deprecated
deprecated
No description
useCaches(bool $use_caches = FALSE)
deprecated
deprecated
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.
getLastInstalledFieldStorageDefinitions($entity_type_id)
deprecated
deprecated
No description
array
getDefinitions()
deprecated
deprecated
Gets the definition of all plugins for this type.
bool
hasDefinition(string $plugin_id)
deprecated
deprecated
Indicates if a specific plugin definition exists.
getActiveDefinition($entity_type_id)
deprecated
deprecated
{@inheritdoc}
object
createInstance(string $plugin_id, array $configuration = [])
deprecated
deprecated
Creates a pre-configured instance of a plugin.
object|false
getInstance(array $options)
deprecated
deprecated
Gets a preconfigured instance of a plugin.
EntityViewDisplayInterface
getViewDisplay(string $entity_type, string $bundle, string $view_mode = self::DEFAULT_DISPLAY_MODE)
deprecated
deprecated
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.
EntityFormDisplayInterface
getFormDisplay(string $entity_type, string $bundle, string $form_mode = self::DEFAULT_DISPLAY_MODE)
deprecated
deprecated
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.