You are here

public function EntityHooks::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/EntityHooks.php, line 59

Class

EntityHooks
Plugin annotation @Converter( id = "entity_hooks", description = @Translation("Rewrites various entity-related hooks."), hook = { "hook_comment_delete", "hook_comment_insert", "hook_comment_presave", "hook_comment_update", …

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter

Code

public function convert(TargetInterface $target, $hook = NULL, $index = 0, $rewriter_id = NULL) {
  $indexer = $target
    ->getIndexer('function');
  if (isset($hook)) {
    if ($indexer
      ->has($hook)) {
      if (empty($rewriter_id)) {

        // Extract the entity type from the hook (e.g. 'hook_node_delete').
        preg_match('/^hook_(.+)_[a-z]+$/', $hook, $matches);
        $rewriter_id = '_rewriter:' . $matches[1];
      }
      $rewriter = $this->rewriters
        ->createInstance($rewriter_id);
      $this
        ->rewriteFunction($rewriter, $indexer
        ->get($hook)
        ->getParameterAtIndex($index), $target);
    }
  }
  else {
    $this
      ->convert($target, 'hook_comment_delete');
    $this
      ->convert($target, 'hook_comment_insert');
    $this
      ->convert($target, 'hook_comment_presave');
    $this
      ->convert($target, 'hook_comment_update');
    $this
      ->convert($target, 'hook_node_access');
    $this
      ->convert($target, 'hook_node_access', 2, '_rewriter:account');
    $this
      ->convert($target, 'hook_node_access_records', 0, '_rewriter:node');
    $this
      ->convert($target, 'hook_node_access_records_alter', 1, '_rewriter:node');
    $this
      ->convert($target, 'hook_node_delete');
    $this
      ->convert($target, 'hook_node_grants', 0, '_rewriter:account');
    $this
      ->convert($target, 'hook_node_grants_alter', 1, '_rewriter:account');
    $this
      ->convert($target, 'hook_node_insert');
    $this
      ->convert($target, 'hook_node_presave');
    $this
      ->convert($target, 'hook_node_revision_delete');
    $this
      ->convert($target, 'hook_node_search_result');
    $this
      ->convert($target, 'hook_node_submit');
    $this
      ->convert($target, 'hook_node_submit', 2, 'form_state');
    $this
      ->convert($target, 'hook_node_update');
    $this
      ->convert($target, 'hook_node_update_index');
    $this
      ->convert($target, 'hook_node_validate');
    $this
      ->convert($target, 'hook_node_validate', 2, 'form_state');
    $this
      ->convert($target, 'hook_taxonomy_term_delete');
    $this
      ->convert($target, 'hook_taxonomy_term_insert');
    $this
      ->convert($target, 'hook_taxonomy_term_presave');
    $this
      ->convert($target, 'hook_taxonomy_term_update');
    $this
      ->convert($target, 'hook_user_delete');
    $this
      ->convert($target, 'hook_user_logout');
  }
}