function RouteSubscriber::addRedirectRoute
Same name in other branches
- 11.x core/modules/block_content/src/Routing/RouteSubscriber.php \Drupal\block_content\Routing\RouteSubscriber::addRedirectRoute()
Adds a redirect route.
Parameters
string $route_name: The name of a route whose path has changed.
1 call to RouteSubscriber::addRedirectRoute()
- RouteSubscriber::alterRoutes in core/
modules/ block_content/ src/ Routing/ RouteSubscriber.php - Alters existing routes for a specific collection.
File
-
core/
modules/ block_content/ src/ Routing/ RouteSubscriber.php, line 124
Class
- RouteSubscriber
- Subscriber for Block content BC routes.
Namespace
Drupal\block_content\RoutingCode
protected function addRedirectRoute(string $route_name) : void {
// Exit early if the BC route is already there.
if (!empty($this->collection
->get("{$route_name}.bc"))) {
return;
}
$route = $this->collection
->get($route_name);
if (empty($route)) {
return;
}
$new_path = $route->getPath();
if (!str_starts_with($new_path, $this->basePath)) {
return;
}
$bc_route = clone $route;
// Set the path to what it was in earlier versions of Drupal.
$bc_route->setPath($this->basePathBc . substr($new_path, strlen($this->basePath)));
if ($bc_route->getPath() === $route->getPath()) {
return;
}
// Replace the handler with the stored redirect controller.
$defaults = array_diff_key($route->getDefaults(), array_flip([
'_entity_form',
'_entity_list',
'_entity_view',
'_form',
]));
$defaults['_controller'] = $this->controller;
$bc_route->setDefaults($defaults);
$this->collection
->add("{$route_name}.bc", $bc_route);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.