protected function ConverterBase::implement in Drupal 7 to 8/9 Module Upgrader 8
Creates an empty implementation of a hook.
Parameters
TargetInterface $target: The target module.
string $hook: The hook to implement, without the hook_ prefix.
Return value
\Pharborist\Functions\FunctionDeclarationNode The hook implementation, appended to the main module file.
File
- src/
ConverterBase.php, line 95
Class
- ConverterBase
- Base class for converters.
Namespace
Drupal\drupalmoduleupgraderCode
protected function implement(TargetInterface $target, $hook) {
$function = FunctionDeclarationNode::create($target
->id() . '_' . $hook);
$function
->setDocComment(DocCommentNode::create('Implements hook_' . $hook . '().'));
$module_file = $target
->getPath('.module');
$target
->open($module_file)
->append($function);
WhitespaceNode::create("\n")
->insertBefore($function);
WhitespaceNode::create("\n")
->insertAfter($function);
return $function;
}