X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FLinks.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FLinks.php;h=386fed4756684caae682da75f283150ae824956b;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Links.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Links.php new file mode 100644 index 000000000..386fed475 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Links.php @@ -0,0 +1,128 @@ +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); + } + } + } + +}