View source
<?php
namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\drupalmoduleupgrader\ConverterBase;
use Drupal\drupalmoduleupgrader\TargetInterface;
use Psr\Log\LoggerInterface;
class EntityHooks extends ConverterBase {
protected $rewriters;
public function __construct(array $configuration, $plugin_id, $plugin_definition, TranslationInterface $translator, LoggerInterface $log, PluginManagerInterface $rewriters) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $translator, $log);
$this->rewriters = $rewriters;
}
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)) {
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');
}
}
}