diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index c1abfe5..563c3b6 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -59,6 +59,7 @@ class CoreBundle extends Bundle $container->register('router.dumper', '\Drupal\Core\Routing\MatcherDumper') ->addArgument(new Reference('database')); $container->register('router.builder', 'Drupal\Core\Routing\RouteBuilder') + ->addArgument(new Reference('config.factory')) ->addArgument(new Reference('router.dumper')); // @todo Replace below lines with the commented out block below it when it's diff --git a/core/lib/Drupal/Core/Routing/RouteBuilder.php b/core/lib/Drupal/Core/Routing/RouteBuilder.php index 6335ffe..80607d2 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php @@ -8,8 +8,10 @@ namespace Drupal\Core\Routing; use Symfony\Component\Routing\RouteCompilerInterface; +use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface; +use Drupal\Core\Config\ConfigFactory; /** * Managing class for rebuilding the router table. @@ -20,6 +22,13 @@ use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface; class RouteBuilder { /** + * The factory for getting configuration objects with routing information. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** * The dumper to which we should send collected routes. * * @var \Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface @@ -29,10 +38,14 @@ class RouteBuilder { /** * Construcs the RouteBuilder using the passed MatcherDumperInterface. * + * @param Drupal\Core\Config\ConfigFactory $configFactory + * The factory for getting configuration objects with routing information. + * * @param Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface $dumper * The matcher dumper used to store the route information. */ - public function __construct(MatcherDumperInterface $dumper) { + public function __construct(ConfigFactory $configFactory, MatcherDumperInterface $dumper) { + $this->configFactory = $configFactory; $this->dumper = $dumper; } @@ -40,14 +53,21 @@ class RouteBuilder { * Rebuilds the route info and dumps to dumper. */ public function rebuild() { - // We need to manually call each module so that we can know which module - // a given item came from. - - foreach (module_implements('route_info') as $module) { - $routes = call_user_func($module . '_route_info'); - drupal_alter('router_info', $routes, $module); - $this->dumper->addRoutes($routes); - $this->dumper->dump(array('route_set' => $module)); + // @todo http://drupal.org/node/1608842 will allow getting the enabled + // modules from the injected ConfigFactory rather than from a global + // function. + foreach (module_list() as $module) { + $routes = $this->configFactory->get($module . '.routing')->load()->get(); + if (!empty($routes)) { + $collection = new RouteCollection(); + foreach ($routes as $name => $route_info) { + $requirements = isset($route_info['requirements']) ? $route_info['requirements'] : array(); + $route = new Route($route_info['pattern'], $route_info['defaults'], $requirements); + $collection->add($name, $route); + } + $this->dumper->addRoutes($collection); + $this->dumper->dump(array('route_set' => $module)); + } } } diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 7957a64..66aa5e8 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -566,51 +566,6 @@ function hook_menu_get_item_alter(&$router_item, $path, $original_map) { } /** - * Defines routes in the new router system. - * - * A route is a Symfony Route object. See the Symfony documentation for more - * details on the available options. Of specific note: - * - _controller: This is the PHP callable that will handle a request matching - * the route. - * - _content: This is the PHP callable that will handle the body of a request - * matching this route. A default controller will provide the page - * rendering around it. - * - * Typically you will only specify one or the other of those properties. - * - * @deprecated - * This mechanism for registering routes is temporary. It will be replaced - * by a more robust mechanism in the near future. It is documented here - * only for completeness. - */ -function hook_route_info() { - $collection = new RouteCollection(); - - $route = new Route('router_test/test1', array( - '_controller' => '\Drupal\router_test\TestControllers::test1' - )); - $collection->add('router_test_1', $route); - - $route = new Route('router_test/test2', array( - '_content' => '\Drupal\router_test\TestControllers::test2' - )); - $collection->add('router_test_2', $route); - - $route = new Route('router_test/test3/{value}', array( - '_content' => '\Drupal\router_test\TestControllers::test3' - )); - $collection->add('router_test_3', $route); - - $route = new Route('router_test/test4/{value}', array( - '_content' => '\Drupal\router_test\TestControllers::test4', - 'value' => 'narf', - )); - $collection->add('router_test_4', $route); - - return $collection; -} - -/** * Define menu items and page callbacks. * * This hook enables modules to register paths in order to define how URL diff --git a/core/modules/system/tests/modules/router_test/config/router_test.routing.yml b/core/modules/system/tests/modules/router_test/config/router_test.routing.yml new file mode 100644 index 0000000..b4965ca --- /dev/null +++ b/core/modules/system/tests/modules/router_test/config/router_test.routing.yml @@ -0,0 +1,20 @@ +router_test_1: + pattern: 'router_test/test1' + defaults: + _controller: '\Drupal\router_test\TestControllers::test1' + +router_test_2: + pattern: 'router_test/test2' + defaults: + _content: '\Drupal\router_test\TestControllers::test2' + +router_test_3: + pattern: 'router_test/test3/{value}' + defaults: + _content: '\Drupal\router_test\TestControllers::test3' + +router_test_4: + pattern: 'router_test/test4/{value}' + defaults: + _content: '\Drupal\router_test\TestControllers::test4' + value: 'narf' diff --git a/core/modules/system/tests/modules/router_test/router_test.module b/core/modules/system/tests/modules/router_test/router_test.module index 4da939d..b3d9bbc 100644 --- a/core/modules/system/tests/modules/router_test/router_test.module +++ b/core/modules/system/tests/modules/router_test/router_test.module @@ -1,34 +1 @@ '\Drupal\router_test\TestControllers::test1' - )); - $collection->add('router_test_1', $route); - - $route = new Route('router_test/test2', array( - '_content' => '\Drupal\router_test\TestControllers::test2' - )); - $collection->add('router_test_2', $route); - - $route = new Route('router_test/test3/{value}', array( - '_content' => '\Drupal\router_test\TestControllers::test3' - )); - $collection->add('router_test_3', $route); - - $route = new Route('router_test/test4/{value}', array( - '_content' => '\Drupal\router_test\TestControllers::test4', - 'value' => 'narf', - )); - $collection->add('router_test_4', $route); - - return $collection; -}