/** * @depends testAddRoute */ public function testFinalize() { $router = new RouterBase(); $user_edit = new RouteWrapper('user.edit', $this->userEdit, $this->routeProvider); $router->addRoute($user_edit); $user_view = new RouteWrapper('user.view', $this->userView, $this->routeProvider); $router->addRoute($user_view); $router->finalize(); $this->assertTrue($user_edit->hasParent()); $this->assertSame($user_view, $user_edit->getParent()); $this->assertTrue($user_view->hasParent()); $this->assertEquals('/user', $user_view->getParent()->getPath()); }
/** * Builds the Drupal 8 router by running the Drupal 7 router items through * the appropriate route converters. * * @return RouterInterface */ private function buildDestinationRoutes() { // @todo These are currently hardcoded on the D7 -> D8 conversion. Make this // configurable. $router = new Drupal8Router(); $this->routeMap = []; foreach ($this->getSourceRoutes() as $path => $route) { /** @var Drupal7\RouteWrapper $route */ // If the route hasn't got a page callback...don't even try. if (!$route->containsKey('page callback')) { continue; } // Get the appropriate route converter, which will build the route // definition. $plugin_id = $route['page callback']; if (!$this->routeConverters->hasDefinition($plugin_id)) { $plugin_id = 'default'; } /** @var Drupal8\RouteWrapper $d8_route */ $d8_route = $this->routeConverters->createInstance($plugin_id)->buildRouteDefinition($this->target, $route); $router->addRoute($d8_route); $this->routeMap[$path] = $d8_route->getIdentifier(); } $router->finalize(); foreach ($this->getSourceRoutes()->getDefaultLocalTasks() as $path => $route) { /** @var Drupal7\RouteWrapper $route */ if ($route->hasParent()) { $parent = (string) $route->getParent()->getPath(); $this->routeMap[$path] = $this->routeMap[$parent]; } } return $router; }