You are here

private function HookMenu::buildDestinationRoutes in Drupal 7 to 8/9 Module Upgrader 8

Builds the Drupal 8 router by running the Drupal 7 router items through the appropriate route converters.

Return value

RouterInterface

1 call to HookMenu::buildDestinationRoutes()
HookMenu::getDestinationRoutes in src/Routing/HookMenu.php
Returns the collection of routes in the destination.

File

src/Routing/HookMenu.php, line 131

Class

HookMenu
This class is a conversion map for hook_menu().

Namespace

Drupal\drupalmoduleupgrader\Routing

Code

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;
}