class EntityResolverManager (View source)

Sets the entity route parameter converter options automatically.

If controllers of routes with route parameters, type-hint the parameters with an entity interface, upcasting is done automatically.

Properties

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager service.

protected ClassResolverInterface $classResolver

The class resolver.

Methods

__construct(EntityTypeManagerInterface $entity_type_manager, ClassResolverInterface $class_resolver)

Constructs a new EntityRouteAlterSubscriber.

string|null
getControllerClass(array $defaults)

Gets the controller class using route defaults.

bool
setParametersFromReflection(string|array $controller, Route $route)

Sets the upcasting information using reflection.

setParametersFromEntityInformation(Route $route)

Sets the upcasting information using the entity* route defaults.

setRouteOptions(Route $route)

Set the upcasting route objects.

getEntityTypes()

Gets the list of all entity types.

Details

__construct(EntityTypeManagerInterface $entity_type_manager, ClassResolverInterface $class_resolver)

Constructs a new EntityRouteAlterSubscriber.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager service.

ClassResolverInterface $class_resolver

The class resolver.

protected string|null getControllerClass(array $defaults)

Gets the controller class using route defaults.

By design we cannot support all possible routes, but just the ones which use the defaults provided by core, which are _controller and _form.

Rather than creating an instance of every controller determine the class and method that would be used. This is not possible for the service:method notation as the runtime container does not allow static introspection.

Parameters

array $defaults

The default values provided by the route.

Return Value

string|null

Returns the controller class, otherwise NULL.

See also

ControllerResolver::getControllerFromDefinition
\Drupal\Core\Controller\ClassResolver::getInstanceFromDefinition()

protected bool setParametersFromReflection(string|array $controller, Route $route)

Sets the upcasting information using reflection.

Parameters

string|array $controller

A PHP callable representing the controller.

Route $route

The route object to populate without upcasting information.

Return Value

bool

Returns TRUE if the upcasting parameters could be set, FALSE otherwise.

protected setParametersFromEntityInformation(Route $route)

Sets the upcasting information using the entity* route defaults.

Supports the '_entity_view' and '_entity_form' route defaults.

Parameters

Route $route

The route object.

setRouteOptions(Route $route)

Set the upcasting route objects.

Parameters

Route $route

The route object to add the upcasting information onto.

protected EntityTypeInterface[] getEntityTypes()

Gets the list of all entity types.

Return Value

EntityTypeInterface[]