HookFormAlter.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Analyzer/HookFormAlter.php
View source
<?php
namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer;
use Drupal\drupalmoduleupgrader\AnalyzerBase;
use Drupal\drupalmoduleupgrader\TargetInterface;
use Pharborist\Filter;
use Pharborist\Functions\FunctionDeclarationNode;
class HookFormAlter extends AnalyzerBase {
public function analyze(TargetInterface $target) {
$violations = [];
$indexer = $target
->getIndexer('function');
if ($indexer
->has('hook_form_alter')) {
$violations[] = $indexer
->get('hook_form_alter');
}
$query = $target
->getIndexer('function')
->getQuery();
$alter_hooks = $query
->condition('id', $query
->escapeLike($target
->id() . '_form_') . '%' . $query
->escapeLike('_alter'), 'LIKE')
->execute();
foreach ($alter_hooks as $alter_hook) {
$violations[] = $target
->open($alter_hook->file)
->find(Filter::isFunction($alter_hook->id))
->get(0);
}
$issues = [];
if ($violations) {
$issue = $this
->buildIssue($target);
array_walk($violations, function (FunctionDeclarationNode $function) use ($issue) {
$issue
->addViolation($function, $this);
});
$issues[] = $issue;
}
return $issues;
}
}
Classes
Name |
Description |
HookFormAlter |
Plugin annotation
@Analyzer(
id = "hook_form_alter",
description = @Translation("Checks for outdated hook_form_alter() implementations."),
documentation = {
{
"url" =… |