public function HookUserLogin::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/ HookUserLogin.php, line 36
Class
- HookUserLogin
- Plugin annotation @Converter( id = "hook_user_login", description = @Translation("Alters signatures of hook_user_login() implementations."), hook = "hook_user_login", 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_user_login');
// The $edit parameter is defunct in Drupal 8, but we'll leave it in
// there as an empty array to prevent errors, and move it to the back
// of the line.
/** @var \Pharborist\Functions\ParameterNode $edit */
$edit = $function
->getParameterList()
->shift()
->setReference(FALSE)
->setValue(ArrayNode::create([]));
$function
->appendParameter($edit);
// Slap a FIXME on the hook implementation, informing the developer that
// $edit and $category are dead.
$comment = $function
->getDocComment();
$comment_text = $comment ? $comment
->getCommentText() : '';
if ($comment_text) {
$comment_text .= "\n\n";
}
$comment_text .= <<<'END'
@FIXME
The $edit parameter is gone in Drupal 8. It has been left here in order to
prevent 'undefined variable' errors, but it will never actually be passed to
this hook. You'll need to modify this function and remove every reference to it.
END;
$function
->setDocComment(DocCommentNode::create($comment_text));
$rewriter = $this->rewriters
->createInstance('_rewriter:user');
$this
->rewriteFunction($rewriter, $function
->getParameterAtIndex(0), $target);
$target
->save($function);
}