3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
5 use Drupal\Component\Plugin\PluginManagerInterface;
6 use Drupal\Core\StringTranslation\TranslationInterface;
7 use Drupal\drupalmoduleupgrader\ConverterBase;
8 use Drupal\drupalmoduleupgrader\TargetInterface;
9 use Pharborist\DocCommentNode;
10 use Pharborist\Types\ArrayNode;
11 use Psr\Log\LoggerInterface;
15 * id = "hook_user_login",
16 * description = @Translation("Alters signatures of hook_user_login() implementations."),
17 * hook = "hook_user_login",
18 * dependencies = { "plugin.manager.drupalmoduleupgrader.rewriter" }
21 class HookUserLogin extends ConverterBase {
24 * @var \Drupal\Component\Plugin\PluginManagerInterface
28 public function __construct(array $configuration, $plugin_id, $plugin_definition, TranslationInterface $translator, LoggerInterface $log, PluginManagerInterface $rewriters) {
29 parent::__construct($configuration, $plugin_id, $plugin_definition, $translator, $log);
30 $this->rewriters = $rewriters;
36 public function convert(TargetInterface $target) {
37 /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
38 $function = $target->getIndexer('function')->get('hook_user_login');
39 // The $edit parameter is defunct in Drupal 8, but we'll leave it in
40 // there as an empty array to prevent errors, and move it to the back
42 /** @var \Pharborist\Functions\ParameterNode $edit */
43 $edit = $function->getParameterList()->shift()->setReference(FALSE)->setValue(ArrayNode::create([]));
44 $function->appendParameter($edit);
46 // Slap a FIXME on the hook implementation, informing the developer that
47 // $edit and $category are dead.
48 $comment = $function->getDocComment();
49 $comment_text = $comment ? $comment->getCommentText() : '';
51 $comment_text .= "\n\n";
53 $comment_text .= <<<'END'
55 The $edit parameter is gone in Drupal 8. It has been left here in order to
56 prevent 'undefined variable' errors, but it will never actually be passed to
57 this hook. You'll need to modify this function and remove every reference to it.
59 $function->setDocComment(DocCommentNode::create($comment_text));
61 $rewriter = $this->rewriters->createInstance('_rewriter:user');
62 $this->rewriteFunction($rewriter, $function->getParameterAtIndex(0), $target);
63 $target->save($function);