public function HookBoot::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/ HookBoot.php, line 21
Class
- HookBoot
- Plugin annotation @Converter( id = "hook_boot", description = @Translation("Converts Drupal 7's hook_boot() to an EventSubscriber."), hook = "hook_boot" )
Namespace
Drupal\drupalmoduleupgrader\Plugin\DMU\ConverterCode
public function convert(TargetInterface $target) {
$this
->writeService($target, 'boot_subscriber', [
'class' => 'Drupal\\' . $target
->id() . '\\EventSubscriber\\BootSubscriber',
'tags' => [
[
'name' => 'event_subscriber',
],
],
]);
$render = [
'#theme' => 'dmu_event_subscriber',
'#module' => $target
->id(),
'#class' => 'BootSubscriber',
'#event' => 'KernelEvents::REQUEST',
];
$subscriber = $this
->parse($render);
$target
->getIndexer('function')
->get('hook_boot')
->cloneAsMethodOf($subscriber)
->setName('onEvent')
->appendParameter(ParameterNode::create('event')
->setTypeHint('\\Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent'));
$this
->writeClass($target, $subscriber);
}