rewriters = $rewriters; } /** * {@inheritdoc} */ 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); } }