You are here

public function HookFormAlter::convert in Drupal 7 to 8/9 Module Upgrader 8

Performs required conversions.

Parameters

TargetInterface $target: The target module to convert.

Overrides ConverterInterface::convert

File

src/Plugin/DMU/Converter/HookFormAlter.php, line 20

Class

HookFormAlter
Plugin annotation @Converter( id = "hook_form_alter", description = @Translation("Corrects hook_form_alter() function signatures.") )

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter

Code

public function convert(TargetInterface $target) {
  $indexer = $target
    ->getIndexer('function');
  $query = $indexer
    ->getQuery();
  $db_or = new Condition('OR');
  $db_or
    ->condition('id', $target
    ->id() . '_form_alter');
  $db_or
    ->condition('id', $query
    ->escapeLike($target
    ->id() . '_form_') . '%' . $query
    ->escapeLike('_alter'), 'LIKE');
  $query
    ->condition($db_or);
  $alter_hooks = $query
    ->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);
    }
  }
}