public function AmpContext::isAmpRoute in Accelerated Mobile Pages (AMP) 8.3
Same name and namespace in other branches
- 8 src/Routing/AmpContext.php \Drupal\amp\Routing\AmpContext::isAmpRoute()
- 8.2 src/Routing/AmpContext.php \Drupal\amp\Routing\AmpContext::isAmpRoute()
Determines whether the active route is an AMP route.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.
mixed $entity: The entity to assess, if any.
boolean $checkTheme: Whether or not to check the active theme as a part of the test.
Return value
bool Returns TRUE if the route is an AMP route, otherwise FALSE.
File
- src/
Routing/ AmpContext.php, line 89
Class
- AmpContext
- Provides a helper class to determine whether the route is an amp one.
Namespace
Drupal\amp\RoutingCode
public function isAmpRoute(RouteMatchInterface $routeMatch = NULL, $entity = NULL, $checkTheme = TRUE) {
if (!$routeMatch) {
$routeMatch = $this->routeMatch;
}
// Some routes cannot be AMP.
if ($route_is_not_amp = $this
->routeIsNotAmp($routeMatch)) {
return FALSE;
}
// Some routes must be AMP.
if ($route_is_amp = $this
->routeIsAmp($routeMatch)) {
return TRUE;
}
// If we have an entity, we can test it.
$route_entity = $this
->routeEntity($routeMatch);
if ($entity instanceof \Drupal\node\NodeInterface || $route_entity instanceof \Drupal\node\NodeInterface) {
$entity_is_amp = $this
->entityIsAmp($entity);
$route_entity_is_amp = $this
->entityIsAmp($route_entity);
return $entity_is_amp || $route_entity_is_amp;
}
// Otherwise, check the active theme.
if ($checkTheme) {
return $this
->routeThemeisAmp($routeMatch);
}
return FALSE;
}