Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookUserLogin.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
4
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;
12
13 /**
14  * @Converter(
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" }
19  * )
20  */
21 class HookUserLogin extends ConverterBase {
22
23   /**
24    * @var \Drupal\Component\Plugin\PluginManagerInterface
25    */
26   protected $rewriters;
27
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;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
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
41     // of the line.
42     /** @var \Pharborist\Functions\ParameterNode $edit */
43     $edit = $function->getParameterList()->shift()->setReference(FALSE)->setValue(ArrayNode::create([]));
44     $function->appendParameter($edit);
45
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() : '';
50     if ($comment_text) {
51       $comment_text .= "\n\n";
52     }
53     $comment_text .= <<<'END'
54 @FIXME
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.
58 END;
59     $function->setDocComment(DocCommentNode::create($comment_text));
60
61     $rewriter = $this->rewriters->createInstance('_rewriter:user');
62     $this->rewriteFunction($rewriter, $function->getParameterAtIndex(0), $target);
63     $target->save($function);
64   }
65
66 }