Issue #2170589 by damiankloip: Use addCollection() in routeBuilder if a RouteCollection is returned from a route_callback.

8.0.x
webchick 2014-01-23 23:08:28 -08:00
parent 02b19f340a
commit 98e3ece396
1 changed files with 13 additions and 5 deletions

View File

@ -112,18 +112,26 @@ class RouteBuilder {
// 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)) {
// 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);
}
}
}
}
unset($routes['route_callbacks']);
}
foreach ($routes as $name => $route_info) {