You are here

public function Routing::convert in Drupal 7 to 8/9 Module Upgrader 8

Performs required conversions.

Parameters

TargetInterface $target: The target module to convert.

Overrides ConverterInterface::convert

File

src/Plugin/DMU/Converter/Routing.php, line 58

Class

Routing
Plugin annotation @Converter( id = "routing", description = @Translation("Converts parts of hook_menu() to the Drupal 8 routing system."), hook = "hook_menu", fixme = @Translation("@FIXME This implementation of hook_menu() cannot be automatically…

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter

Code

public function convert(TargetInterface $target) {

  // If the hook implementation contains logic, we cannot convert it and
  // that's that. So we'll leave a FIXME and bail out.

  /** @var \Pharborist\Functions\FunctionDeclarationNode $hook */
  $hook = $target
    ->getIndexer('function')
    ->get('hook_menu');
  if ($hook
    ->is(new ContainsLogicFilter())) {
    $hook
      ->setDocComment(DocCommentNode::create($this->pluginDefinition['fixme']));
    $target
      ->save($hook);
    return;
  }
  $hook_menu = new HookMenu($target, $this->routeConverters);
  foreach ($hook_menu
    ->getSourceRoutes() as $path => $route) {

    /** @var \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper $route */
    if ($route
      ->containsKey('page callback')) {
      $plugin_id = $this->routeConverters
        ->hasDefinition($route['page callback']) ? $route['page callback'] : 'default';

      /** @var \Drupal\drupalmoduleupgrader\Routing\RouteConverterInterface $converter */
      $this->routeConverters
        ->createInstance($plugin_id)
        ->buildRoute($target, $route);
    }
  }
  $routing = [];
  foreach ($hook_menu
    ->getDestinationRoutes() as $name => $route) {
    $routing[$name] = [
      'path' => $route
        ->getPath()
        ->__toString(),
      'defaults' => $route
        ->getDefaults(),
      'requirements' => $route
        ->getRequirements(),
    ];
  }
  $this
    ->writeInfo($target, 'routing', $routing);
}