interface EntityTypeManagerInterface implements PluginManagerInterface, CachedDiscoveryInterface (View source)

Provides an interface for entity type managers.

Methods

mixed
getDefinition($entity_type_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.

Details

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

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

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.

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

An 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\EntityTypeManagerInterface::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.