public function HookNodePrepare::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/ HookNodePrepare.php, line 35
Class
- 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" } )
Namespace
Drupal\drupalmoduleupgrader\Plugin\DMU\ConverterCode
public function convert(TargetInterface $target) {
/** @var \Pharborist\Functions\FunctionDeclarationNode $function */
$function = $target
->getIndexer('function')
->get('hook_node_prepare');
// foo_node_prepare() --> foo_node_prepare_form().
$function
->setName($function
->getName() . '_form');
// The first parameter is a node, so rewrite the function accordingly.
$this->rewriters
->createInstance('_entity:node')
->rewrite($function
->getParameterAtIndex(0));
// Create the $operation parameter.
$function
->appendParameter(ParameterNode::create('operation'));
// Create the $form_state parameter.
$form_state = ParameterNode::create('form_state')
->setTypeHint('\\Drupal\\Core\\Form\\FormStateInterface');
$function
->appendParameter($form_state);
$target
->save($function);
}