routeConverters = $route_converters; $this->linkBinding = $link_binding; } /** * {@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); } } } }