Skip to content
Snippets Groups Projects
Commit 98e3ece3 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2170589 by damiankloip: Use addCollection() in routeBuilder if a...

Issue #2170589 by damiankloip: Use addCollection() in routeBuilder if a RouteCollection is returned from a route_callback.
parent 02b19f34
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -112,15 +112,23 @@ public function rebuild() {
// The top-level 'routes_callback' is a list of methods in controller
// syntax, see \Drupal\Core\Controller\ControllerResolver. These methods
// should return a set of \Symfony\Component\Routing\Route objects, either
// in an associative array keyed by the route name, or as a new
// \Symfony\Component\Routing\RouteCollection, which will be iterated over
// and added to the collection for this provider.
// in an associative array keyed by the route name, which will be iterated
// over and added to the collection for this provider, or as a new
// \Symfony\Component\Routing\RouteCollection object, which will be added
// to the collection.
if (isset($routes['route_callbacks'])) {
foreach ($routes['route_callbacks'] as $route_callback) {
$callback = $this->controllerResolver->getControllerFromDefinition($route_callback);
if ($callback_routes = call_user_func($callback)) {
foreach ($callback_routes as $name => $callback_route) {
$collection->add($name, $callback_route);
// If a RouteCollection is returned, add the whole collection.
if ($callback_routes instanceof RouteCollection) {
$collection->addCollection($callback_routes);
}
// Otherwise, add each Route object individually.
else {
foreach ($callback_routes as $name => $callback_route) {
$collection->add($name, $callback_route);
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment