Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookInit.php
diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookInit.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookInit.php
new file mode 100644 (file)
index 0000000..0d13efd
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
+
+use Drupal\drupalmoduleupgrader\ConverterBase;
+use Drupal\drupalmoduleupgrader\TargetInterface;
+
+/**
+ * @Converter(
+ *  id = "hook_init",
+ *  description = @Translation("Converts Drupal 7's hook_init() to an EventSubscriber."),
+ *  hook = "hook_init"
+ * )
+ */
+class HookInit extends ConverterBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function convert(TargetInterface $target) {
+    $this->writeService($target, 'init_subscriber', [
+      'class' => 'Drupal\\' . $target->id() . '\\EventSubscriber\\InitSubscriber',
+      'tags' => [
+        [ 'name' => 'event_subscriber' ],
+      ],
+    ]);
+
+    $render = [
+      '#theme' => 'dmu_event_subscriber',
+      '#module' => $target->id(),
+      '#class' => 'InitSubscriber',
+      '#event' => 'KernelEvents::REQUEST',
+    ];
+    $subscriber = $this->parse($render);
+    $target
+      ->getIndexer('function')
+      ->get('hook_init')
+      ->cloneAsMethodOf($subscriber)
+      ->setName('onEvent');
+    $this->writeClass($target, $subscriber);
+  }
+
+}