Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 9 |
Uid | |
0.00% |
0 / 1 |
|
25.00% |
1 / 4 |
20 | |
0.00% |
0 / 9 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
titleQuery | |
100.00% |
1 / 1 |
1 | |
100.00% |
0 / 0 |
|||
anonymous function | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\user\Plugin\views\argument\Uid. | |
*/ | |
namespace Drupal\user\Plugin\views\argument; | |
use Drupal\Core\Entity\EntityStorageInterface; | |
use Drupal\views\Plugin\views\argument\NumericArgument; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* Argument handler to accept a user id. | |
* | |
* @ingroup views_argument_handlers | |
* | |
* @ViewsArgument("user_uid") | |
*/ | |
class Uid extends NumericArgument { | |
/** | |
* The user storage. | |
* | |
* @var \Drupal\Core\Entity\EntityStorageInterface | |
*/ | |
protected $storage; | |
/** | |
* Constructs a Drupal\Component\Plugin\PluginBase object. | |
* | |
* @param array $configuration | |
* A configuration array containing information about the plugin instance. | |
* @param string $plugin_id | |
* The plugin_id for the plugin instance. | |
* @param mixed $plugin_definition | |
* The plugin implementation definition. | |
* @param \Drupal\Core\Entity\EntityStorageInterface $storage | |
* The user storage. | |
*/ | |
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $storage) { | |
parent::__construct($configuration, $plugin_id, $plugin_definition); | |
$this->storage = $storage; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | |
return new static($configuration, $plugin_id, $plugin_definition, | |
$container->get('entity.manager')->getStorage('user')); | |
} | |
/** | |
* Override the behavior of title(). Get the name of the user. | |
* | |
* @return array | |
* A list of usernames. | |
*/ | |
public function titleQuery() { | |
return array_map(function($account) { | |
return $account->label(); | |
}, $this->storage->loadMultiple($this->value)); | |
} | |
} |