Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / user / src / Plugin / views / argument / Uid.php
1 <?php
2
3 namespace Drupal\user\Plugin\views\argument;
4
5 use Drupal\Core\Entity\EntityStorageInterface;
6 use Drupal\views\Plugin\views\argument\NumericArgument;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 /**
10  * Argument handler to accept a user id.
11  *
12  * @ingroup views_argument_handlers
13  *
14  * @ViewsArgument("user_uid")
15  */
16 class Uid extends NumericArgument {
17
18   /**
19    * The user storage.
20    *
21    * @var \Drupal\Core\Entity\EntityStorageInterface
22    */
23   protected $storage;
24
25   /**
26    * Constructs a \Drupal\user\Plugin\views\argument\Uid object.
27    *
28    * @param array $configuration
29    *   A configuration array containing information about the plugin instance.
30    * @param string $plugin_id
31    *   The plugin_id for the plugin instance.
32    * @param mixed $plugin_definition
33    *   The plugin implementation definition.
34    * @param \Drupal\Core\Entity\EntityStorageInterface $storage
35    *   The user storage.
36    */
37   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $storage) {
38     parent::__construct($configuration, $plugin_id, $plugin_definition);
39     $this->storage = $storage;
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
46     return new static($configuration, $plugin_id, $plugin_definition,
47       $container->get('entity.manager')->getStorage('user'));
48   }
49
50   /**
51    * Override the behavior of title(). Get the name of the user.
52    *
53    * @return array
54    *   A list of usernames.
55    */
56   public function titleQuery() {
57     return array_map(function ($account) {
58       return $account->label();
59     }, $this->storage->loadMultiple($this->value));
60   }
61
62 }