Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookFormAlter.php
diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookFormAlter.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookFormAlter.php
new file mode 100644 (file)
index 0000000..0ee54c2
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
+
+use Drupal\drupalmoduleupgrader\ConverterBase;
+use Drupal\drupalmoduleupgrader\TargetInterface;
+
+/**
+ * @Converter(
+ *  id = "hook_form_alter",
+ *  description = @Translation("Corrects hook_form_alter() function signatures.")
+ * )
+ */
+class HookFormAlter extends ConverterBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function convert(TargetInterface $target) {
+    $indexer = $target->getIndexer('function');
+
+    // @FIXME This is not working (returns empty result set)...don't know why.
+    $alter_hooks = $indexer
+      ->getQuery()
+      ->condition(db_or()
+        ->condition('id', $target->id() . '_form_alter')
+        ->condition('id', db_like($target->id() . '_form_%_alter'), 'LIKE')
+      )
+      ->execute();
+
+    foreach ($alter_hooks as $alter_hook) {
+      /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
+      $function = $indexer->get($alter_hook->id);
+
+      $parameters = $function->getParameters();
+      if (sizeof($parameters) > 1) {
+        $parameters[1]->setTypeHint('\Drupal\Core\Form\FormStateInterface');
+        $target->save($function);
+      }
+    }
+  }
+
+}