Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookFormAlter.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
4
5 use Drupal\drupalmoduleupgrader\ConverterBase;
6 use Drupal\drupalmoduleupgrader\TargetInterface;
7
8 /**
9  * @Converter(
10  *  id = "hook_form_alter",
11  *  description = @Translation("Corrects hook_form_alter() function signatures.")
12  * )
13  */
14 class HookFormAlter extends ConverterBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function convert(TargetInterface $target) {
20     $indexer = $target->getIndexer('function');
21
22     // @FIXME This is not working (returns empty result set)...don't know why.
23     $alter_hooks = $indexer
24       ->getQuery()
25       ->condition(db_or()
26         ->condition('id', $target->id() . '_form_alter')
27         ->condition('id', db_like($target->id() . '_form_%_alter'), 'LIKE')
28       )
29       ->execute();
30
31     foreach ($alter_hooks as $alter_hook) {
32       /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
33       $function = $indexer->get($alter_hook->id);
34
35       $parameters = $function->getParameters();
36       if (sizeof($parameters) > 1) {
37         $parameters[1]->setTypeHint('\Drupal\Core\Form\FormStateInterface');
38         $target->save($function);
39       }
40     }
41   }
42
43 }