Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookBoot.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
4
5 use Drupal\drupalmoduleupgrader\ConverterBase;
6 use Drupal\drupalmoduleupgrader\TargetInterface;
7 use Pharborist\Functions\ParameterNode;
8
9 /**
10  * @Converter(
11  *  id = "hook_boot",
12  *  description = @Translation("Converts Drupal 7's hook_boot() to an EventSubscriber."),
13  *  hook = "hook_boot"
14  * )
15  */
16 class HookBoot extends ConverterBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function convert(TargetInterface $target) {
22     $this->writeService($target, 'boot_subscriber', [
23       'class' => 'Drupal\\' . $target->id() . '\\EventSubscriber\\BootSubscriber',
24       'tags' => [
25         [ 'name' => 'event_subscriber' ],
26       ],
27     ]);
28
29     $render = [
30       '#theme' => 'dmu_event_subscriber',
31       '#module' => $target->id(),
32       '#class' => 'BootSubscriber',
33       '#event' => 'KernelEvents::REQUEST',
34     ];
35     $subscriber = $this->parse($render);
36
37     $target
38       ->getIndexer('function')
39       ->get('hook_boot')
40       ->cloneAsMethodOf($subscriber)
41       ->setName('onEvent')
42       ->appendParameter(ParameterNode::create('event')
43         ->setTypeHint('\Symfony\Component\HttpKernel\Event\GetResponseEvent')
44       );
45
46     $this->writeClass($target, $subscriber);
47   }
48
49 }