You are here

HookBoot.php in Drupal 7 to 8/9 Module Upgrader 8

File

src/Plugin/DMU/Converter/HookBoot.php
View source
<?php

namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;

use Drupal\drupalmoduleupgrader\ConverterBase;
use Drupal\drupalmoduleupgrader\TargetInterface;
use Pharborist\Functions\ParameterNode;

/**
 * @Converter(
 *  id = "hook_boot",
 *  description = @Translation("Converts Drupal 7's hook_boot() to an EventSubscriber."),
 *  hook = "hook_boot"
 * )
 */
class HookBoot extends ConverterBase {

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Classes

Namesort descending Description
HookBoot Plugin annotation @Converter( id = "hook_boot", description = @Translation("Converts Drupal 7's hook_boot() to an EventSubscriber."), hook = "hook_boot" )