HookUserLogin.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Converter/HookUserLogin.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\DocCommentNode;
use Pharborist\Types\ArrayNode;
use Psr\Log\LoggerInterface;
class HookUserLogin 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_user_login');
$edit = $function
->getParameterList()
->shift()
->setReference(FALSE)
->setValue(ArrayNode::create([]));
$function
->appendParameter($edit);
$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);
}
}
Classes
Name |
Description |
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" }
) |