3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer;
5 use Drupal\drupalmoduleupgrader\AnalyzerBase;
6 use Drupal\drupalmoduleupgrader\TargetInterface;
8 use Pharborist\Functions\FunctionDeclarationNode;
12 * id = "hook_form_alter",
13 * description = @Translation("Checks for outdated hook_form_alter() implementations."),
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")
21 * "category" = { "form" }
23 * message = @Translation("The signature of hook_form_alter() has changed in Drupal 8.")
26 class HookFormAlter extends AnalyzerBase {
31 public function analyze(TargetInterface $target) {
34 $indexer = $target->getIndexer('function');
35 if ($indexer->has('hook_form_alter')) {
36 $violations[] = $indexer->get('hook_form_alter');
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')) {
45 $alter_hooks = $target
46 ->getIndexer('function')
48 ->condition('id', $id, 'LIKE')
51 foreach ($alter_hooks as $alter_hook) {
52 $violations[] = $target
53 ->open($alter_hook->file)
54 ->find(Filter::isFunction($alter_hook->id));
60 $issue = $this->buildIssue($target);
61 array_walk($violations, function(FunctionDeclarationNode $function) use ($issue) {
62 $issue->addViolation($function, $this);