You are here

private function LayoutBuilder::getEntityTypeFromRoute in Core Context 8

Extracts the entity type ID from the current route.

We expect to be on the Layout Builder UI, which we can identify using the _entity_form default, which will carry a value of ENTITY_TYPE_ID.layout_builder.

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\layout_builder\Routing\LayoutBuilderRoutesTrait

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

File

src/ContextProvider/LayoutBuilder.php, line 60

Class

LayoutBuilder
Exposes contexts available at Layout Builder routes.

Namespace

Drupal\core_context\ContextProvider

Code

private function getEntityTypeFromRoute(Route $route) {
  $match = [];
  preg_match('/([a-zA-Z0-9_]+)\\.layout_builder$/', (string) $route
    ->getDefault('_entity_form'), $match);
  return $match ? $match[1] : NULL;
}