You are here

private function CanonicalEntity::getEntityTypeAndViewModeFromRoute in Core Context 8

Extracts the entity type and view mode from the current route.

We expect to be on a canonical entity route. That means we expect the route to have an _entity_view default which carries the entity type being viewed and the view mode being used, separated by a period. Certain routes, like entity.node.canonical, don't have this default. So our route subscriber polyfills it by adding a _core_context_entity default containing the required information.

Parameters

\Symfony\Component\Routing\Route $route: The current route object.

Return value

string The entity type and view mode, separated by a period. If we are not on a canonical entity route, an empty string is returned.

See also

\Drupal\core_context\Routing\RouteSubscriber::alterRoutes()

2 calls to CanonicalEntity::getEntityTypeAndViewModeFromRoute()
CanonicalEntity::appliesTo in src/ContextProvider/CanonicalEntity.php
Determines if this provider can extract contexts from the current route.
CanonicalEntity::getContextsFromRoute in src/ContextProvider/CanonicalEntity.php
Extracts contexts from the current route.

File

src/ContextProvider/CanonicalEntity.php, line 53

Class

CanonicalEntity
Exposes contexts available at a canonical entity route.

Namespace

Drupal\core_context\ContextProvider

Code

private function getEntityTypeAndViewModeFromRoute(Route $route) : string {
  return strval($route
    ->getDefault('_core_context_entity') ?: $route
    ->getDefault('_entity_view'));
}