public function AmpContext::isAmpRoute in Accelerated Mobile Pages (AMP) 8
Same name and namespace in other branches
- 8.3 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 one.
Parameters
\Symfony\Component\Routing\Route $route: (optional) The route to determine whether it is an amp one. Per default this falls back to the route object on the active request.
Return value
bool Returns TRUE if the route is an amp one, otherwise FALSE.
File
- src/
Routing/ AmpContext.php, line 57 - Contains \Drupal\amp\Routing\AmpContext.
Class
- AmpContext
- Provides a helper class to determine whether the route is an amp one.
Namespace
Drupal\amp\RoutingCode
public function isAmpRoute(Route $route = NULL) {
if (!$route) {
$route = $this->routeMatch
->getRouteObject();
if (!$route) {
return FALSE;
}
}
// Check if the globally-defined AMP status has been changed to TRUE (it
// is FALSE by default).
if ($route
->getOption('_amp_route')) {
return TRUE;
}
// We only want to consider path with amp in the query string.
if (!isset($_GET['amp'])) {
return FALSE;
}
// Load the current node.
$node = $this->routeMatch
->getParameter('node');
// If we only got back the node ID, load the node.
if (!is_object($node) && is_numeric($node)) {
$node = Node::load($node);
}
// Check if we have a node. Will not be true on admin pages for example.
if (is_object($node)) {
$type = $node
->getType();
// Only show AMP routes for content that is AMP enabled.
return $this->entityTypeInfo
->isAmpEnabledType($type);
}
return FALSE;
}