Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Analyzer / HookFormAlter.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer;
4
5 use Drupal\drupalmoduleupgrader\AnalyzerBase;
6 use Drupal\drupalmoduleupgrader\TargetInterface;
7 use Pharborist\Filter;
8 use Pharborist\Functions\FunctionDeclarationNode;
9
10 /**
11  * @Analyzer(
12  *  id = "hook_form_alter",
13  *  description = @Translation("Checks for outdated hook_form_alter() implementations."),
14  *  documentation = {
15  *    {
16  *      "url" = "https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21form.api.php/function/hook_form_alter/8",
17  *      "title" = @Translation("`hook_form_alter()` documentation")
18  *    }
19  *  },
20  *  tags = {
21  *    "category" = { "form" }
22  *  },
23  *  message = @Translation("The signature of hook_form_alter() has changed in Drupal 8.")
24  * )
25  */
26 class HookFormAlter extends AnalyzerBase {
27
28   /**
29    * {@inheritdoc}
30    */
31   public function analyze(TargetInterface $target) {
32     $violations = [];
33
34     $indexer = $target->getIndexer('function');
35     if ($indexer->has('hook_form_alter')) {
36       $violations[] = $indexer->get('hook_form_alter');
37     }
38
39     $id = $target->id() . '_form_%_alter';
40     // Until kernel tests are run in PHPUnit, we need to check for
41     // the existence of db_like().
42     if (function_exists('db_like')) {
43       $id = db_like($id);
44     }
45     $alter_hooks = $target
46       ->getIndexer('function')
47       ->getQuery()
48       ->condition('id', $id, 'LIKE')
49       ->execute();
50
51     foreach ($alter_hooks as $alter_hook) {
52       $violations[] = $target
53         ->open($alter_hook->file)
54         ->find(Filter::isFunction($alter_hook->id));
55     }
56
57     $issues = [];
58
59     if ($violations) {
60       $issue = $this->buildIssue($target);
61       array_walk($violations, function(FunctionDeclarationNode $function) use ($issue) {
62         $issue->addViolation($function, $this);
63       });
64       $issues[] = $issue;
65     }
66
67     return $issues;
68   }
69
70 }