Drupal\helper\CurrentEntity
Provides helper for working with current entities.
Implements:
Drupal\Core\Cache\CacheableDependencyInterface
Methods
| Name | Description |
|---|---|
| __construct | CurrentEntity constructor. |
| fromContextId | Get the entity from a context ID. |
| fromLayoutBuilderContext | Gets the current layout builder entity. |
| fromRouteAndParameters | Gets the entity from a route and its parameters. |
| fromRouteMatch | Gets the entity from a route match. |
| getCacheContexts | {@inheritdoc} |
| getCacheMaxAge | {@inheritdoc} |
| getCacheTags | {@inheritdoc} |
CurrentEntity::__construct
Description
public __construct (\Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler, \Drupal\Core\Routing\RouteMatchInterface $routeMatch, \Drupal\Core\Plugin\Context\ContextRepositoryInterface $contextRepository, \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager)
CurrentEntity constructor.
Parameters
(\Drupal\Core\Extension\ModuleHandlerInterface) $moduleHandler:
The module handler.(\Drupal\Core\Routing\RouteMatchInterface) $routeMatch:
Route match.(\Drupal\Core\Plugin\Context\ContextRepositoryInterface) $contextRepository:
The context repository.(\Drupal\Core\Entity\EntityTypeManagerInterface) $entityTypeManager:
The entity type manager.
Return Values
void
CurrentEntity::fromContextId
Description
public fromContextId (void)
Get the entity from a context ID.
Parameters
This function has no parameters.
Return Values
\Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\EntityTypeInterface|null
The context entity or entity type if available.
Throws Exceptions
\Drupal\Component\Plugin\Exception\ContextException
If the context was not found.
CurrentEntity::fromLayoutBuilderContext
Description
public fromLayoutBuilderContext (void)
Gets the current layout builder entity.
Parameters
This function has no parameters.
Return Values
\Drupal\Core\Entity\EntityInterface|null
The current layout entity context.
CurrentEntity::fromRouteAndParameters
Description
public fromRouteAndParameters (string $routeName, \Symfony\Component\HttpFoundation\ParameterBag $parameters)
Gets the entity from a route and its parameters.
Parameters
(string) $routeName:
The route name.(\Symfony\Component\HttpFoundation\ParameterBag) $parameters:
The route parameters.
Return Values
\Drupal\Core\Entity\EntityInterface|null
The route's entity, or NULL if this is not an entity route.
CurrentEntity::fromRouteMatch
Description
public fromRouteMatch (\Drupal\Core\Routing\RouteMatchInterface|null $routeMatch)
Gets the entity from a route match.
Parameters
(\Drupal\Core\Routing\RouteMatchInterface|null) $routeMatch:
The route match to use, otherwise uses the current route match.
Return Values
\Drupal\Core\Entity\EntityInterface|null
The current page entity, or NULL if this is not an entity route.
CurrentEntity::getCacheContexts
Description
public getCacheContexts (void)
{@inheritdoc}
Parameters
This function has no parameters.
Return Values
void
CurrentEntity::getCacheMaxAge
Description
public getCacheMaxAge (void)
{@inheritdoc}
Parameters
This function has no parameters.
Return Values
void
CurrentEntity::getCacheTags
Description
public getCacheTags (void)
{@inheritdoc}
Parameters
This function has no parameters.
Return Values
void