1<?php 2 3namespace Drupal\user\Plugin\views\argument; 4 5use Drupal\Core\Entity\EntityStorageInterface; 6use Drupal\views\Plugin\views\argument\NumericArgument; 7use 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 */ 16class 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( 47 $configuration, 48 $plugin_id, 49 $plugin_definition, 50 $container->get('entity_type.manager')->getStorage('user') 51 ); 52 } 53 54 /** 55 * Override the behavior of title(). Get the name of the user. 56 * 57 * @return array 58 * A list of usernames. 59 */ 60 public function titleQuery() { 61 return array_map(function ($account) { 62 return $account->label(); 63 }, $this->storage->loadMultiple($this->value)); 64 } 65 66} 67