public function PathPluginBase::alterRoutes in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Plugin/views/display/PathPluginBase.php \Drupal\views\Plugin\views\display\PathPluginBase::alterRoutes()
Alters a collection of routes and replaces definitions to the view.
Most of the collections won't have the needed route, so by the return value the method can specify to break the search.
Parameters
\Symfony\Component\Routing\RouteCollection $collection:
Return value
array Returns a list of "$view_id.$display_id" elements which got overridden.
Overrides DisplayRouterInterface::alterRoutes
File
- core/
modules/ views/ src/ Plugin/ views/ display/ PathPluginBase.php, line 237 - Contains \Drupal\views\Plugin\views\display\PathPluginBase.
Class
- PathPluginBase
- The base display plugin for path/callbacks. This is used for pages and feeds.
Namespace
Drupal\views\Plugin\views\displayCode
public function alterRoutes(RouteCollection $collection) {
$view_route_names = array();
$view_path = $this
->getPath();
foreach ($collection
->all() as $name => $route) {
// Find all paths which match the path of the current display..
$route_path = RouteCompiler::getPathWithoutDefaults($route);
$route_path = RouteCompiler::getPatternOutline($route_path);
// Ensure that we don't override a route which is already controlled by
// views.
if (!$route
->hasDefault('view_id') && '/' . $view_path == $route_path) {
$parameters = $route
->compile()
->getPathVariables();
// @todo Figure out whether we need to merge some settings (like
// requirements).
// Replace the existing route with a new one based on views.
$original_route = $collection
->get($name);
$collection
->remove($name);
$view_id = $this->view->storage
->id();
$display_id = $this->display['id'];
$route = $this
->getRoute($view_id, $display_id);
$path = $route
->getPath();
// Replace the path with the original parameter names and add a mapping.
$argument_map = array();
// We assume that the numeric ids of the parameters match the one from
// the view argument handlers.
foreach ($parameters as $position => $parameter_name) {
$path = str_replace('{arg_' . $position . '}', '{' . $parameter_name . '}', $path);
$argument_map['arg_' . $position] = $parameter_name;
}
// Copy the original options from the route, so for example we ensure
// that parameter conversion options is carried over.
$route
->setOptions($route
->getOptions() + $original_route
->getOptions());
// Set the corrected path and the mapping to the route object.
$route
->setOption('_view_argument_map', $argument_map);
$route
->setPath($path);
$collection
->add($name, $route);
$view_route_names[$view_id . '.' . $display_id] = $name;
}
}
return $view_route_names;
}