RolesRid.php in Drupal 8
File
core/modules/user/src/Plugin/views/argument/RolesRid.php
View source
<?php
namespace Drupal\user\Plugin\views\argument;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\views\Plugin\views\argument\ManyToOne;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RolesRid extends ManyToOne {
protected $roleStorage;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->roleStorage = $entity_type_manager
->getStorage('user_role');
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
}
public function titleQuery() {
$entities = $this->roleStorage
->loadMultiple($this->value);
$titles = [];
foreach ($entities as $entity) {
$titles[] = $entity
->label();
}
return $titles;
}
}