public function HookExit::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/ HookExit.php, line 20
Class
- HookExit
- Plugin annotation @Converter( id = "hook_exit", description = @Translation("Converts Drupal 7's hook_exit() to an EventSubscriber."), hook = "hook_exit" )
Namespace
Drupal\drupalmoduleupgrader\Plugin\DMU\ConverterCode
public function convert(TargetInterface $target) {
$this
->writeService($target, 'exit_subscriber', [
'class' => 'Drupal\\' . $target
->id() . '\\EventSubscriber\\ExitSubscriber',
'tags' => [
[
'name' => 'event_subscriber',
],
],
]);
$render = [
'#theme' => 'dmu_event_subscriber',
'#module' => $target
->id(),
'#class' => 'ExitSubscriber',
'#event' => 'KernelEvents::TERMINATE',
];
$subscriber = $this
->parse($render);
$target
->getIndexer('function')
->get('hook_exit')
->cloneAsMethodOf($subscriber)
->setName('onEvent');
$this
->writeClass($target, $subscriber);
}