/** * {@inheritdoc} */ 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); }
/** * {@inheritdoc} */ 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; } // Links are split out by group because there are separate config files // for each link type. $links = ['menu' => new LinkIndex(), 'task' => new LinkIndex(), 'action' => new LinkIndex(), 'contextual' => new LinkIndex()]; $hook_menu = new HookMenu($target, $this->routeConverters); foreach ($hook_menu->getSourceRoutes()->getAllLinks() as $path => $source) { /** @var LinkBinding $binding */ $binding = $this->linkBinding->create($source, $hook_menu->getDestinationRoute($path)); // Skip if the converter wasn't able to find a destination. $destination = $binding->getDestination(); if (empty($destination)) { continue; } if ($binding instanceof MenuLinkBinding) { $links['menu']->addBinding($binding); } elseif ($binding instanceof LocalTaskLinkBinding) { $links['task']->addBinding($binding); } elseif ($binding instanceof LocalActionLinkBinding) { $links['action']->addBinding($binding); } elseif ($source->isContextualLink()) { $links['contextual']->addBinding($binding); } } $links = array_map(function (LinkIndex $index) { return $index->build(); }, $links); foreach ($links['contextual'] as $link) { $link['group'] = $target->id(); } foreach ($links as $group => $data) { if ($data) { $this->writeInfo($target, 'links.' . $group, $data); } } }