Routing.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Converter/Routing.php
View source
<?php
namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\drupalmoduleupgrader\ConverterBase;
use Drupal\drupalmoduleupgrader\Routing\HookMenu;
use Drupal\drupalmoduleupgrader\TargetInterface;
use Drupal\drupalmoduleupgrader\Utility\Filter\ContainsLogicFilter;
use Pharborist\DocCommentNode;
use Psr\Log\LoggerInterface;
class Routing extends ConverterBase {
protected $routeConverters;
public function __construct(array $configuration, $plugin_id, $plugin_definition, TranslationInterface $translator, LoggerInterface $log, PluginManagerInterface $route_converters) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $translator, $log);
$this->routeConverters = $route_converters;
}
public function convert(TargetInterface $target) {
$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) {
if ($route
->containsKey('page callback')) {
$plugin_id = $this->routeConverters
->hasDefinition($route['page callback']) ? $route['page callback'] : 'default';
$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);
}
}
Classes
Name |
Description |
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… |