protected function VariantRouteFilter::getVariantRouteName in Page Manager 8
Same name and namespace in other branches
- 8.4 src/Routing/VariantRouteFilter.php \Drupal\page_manager\Routing\VariantRouteFilter::getVariantRouteName()
Gets the route name of the first valid variant.
Parameters
\Symfony\Component\Routing\Route[] $routes: An array of sorted routes.
\Symfony\Component\HttpFoundation\Request $request: A current request.
Return value
string|null A route name, or NULL if none are found.
1 call to VariantRouteFilter::getVariantRouteName()
- VariantRouteFilter::filter in src/
Routing/ VariantRouteFilter.php - Ensures only one page manager route remains in the collection.
File
- src/
Routing/ VariantRouteFilter.php, line 124 - Contains \Drupal\page_manager\Routing\VariantRouteFilter.
Class
- VariantRouteFilter
- Filters variant routes.
Namespace
Drupal\page_manager\RoutingCode
protected function getVariantRouteName(array $routes, Request $request) {
// Store the unaltered request attributes.
$original_attributes = $request->attributes
->all();
foreach ($routes as $name => $route) {
if (!($page_variant_id = $route
->getDefault('page_manager_page_variant'))) {
continue;
}
if ($attributes = $this
->getRequestAttributes($route, $name, $request)) {
// Use the overridden route name if available.
$attributes[RouteObjectInterface::ROUTE_NAME] = $route
->getDefault('overridden_route_name') ?: $name;
// Add the enhanced attributes to the request.
$request->attributes
->add($attributes);
$this->requestStack
->push($request);
if ($this
->checkPageVariantAccess($page_variant_id)) {
$this->requestStack
->pop();
return $name;
}
// Restore the original request attributes, this must be done in the loop
// or the request attributes will not be calculated correctly for the
// next route.
$request->attributes
->replace($original_attributes);
$this->requestStack
->pop();
}
}
}