HookNodePrepare.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Converter/HookNodePrepare.php
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 Pharborist\Functions\ParameterNode;
use Psr\Log\LoggerInterface;
class HookNodePrepare 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) {
$function = $target
->getIndexer('function')
->get('hook_node_prepare');
$function
->setName($function
->getName() . '_form');
$this->rewriters
->createInstance('_entity:node')
->rewrite($function
->getParameterAtIndex(0));
$function
->appendParameter(ParameterNode::create('operation'));
$form_state = ParameterNode::create('form_state')
->setTypeHint('\\Drupal\\Core\\Form\\FormStateInterface');
$function
->appendParameter($form_state);
$target
->save($function);
}
}
Classes
Name |
Description |
HookNodePrepare |
Plugin annotation
@Converter(
id = "hook_node_prepare",
description = @Translation("Converts hook_node_prepare() into hook_ENTITY_TYPE_prepare_form()."),
hook = "hook_node_prepare",
dependencies = { "plugin.manager.drupalmoduleupgrader.rewriter" }
) |