You are here

class RolesRid in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/src/Plugin/views/argument/RolesRid.php \Drupal\user\Plugin\views\argument\RolesRid
  2. 9 core/modules/user/src/Plugin/views/argument/RolesRid.php \Drupal\user\Plugin\views\argument\RolesRid

Allow role ID(s) as argument.

Plugin annotation

@ViewsArgument("user__roles_rid");

Hierarchy

  • class \Drupal\user\Plugin\views\argument\RolesRid extends \Drupal\views\Plugin\views\argument\ManyToOne

Expanded class hierarchy of RolesRid

1 file declares its use of RolesRid
RolesRidTest.php in core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php

File

core/modules/user/src/Plugin/views/argument/RolesRid.php, line 16

Namespace

Drupal\user\Plugin\views\argument
View source
class RolesRid extends ManyToOne {

  /**
   * The role entity storage.
   *
   * @var \Drupal\user\RoleStorage
   */
  protected $roleStorage;

  /**
   * Constructs a \Drupal\user\Plugin\views\argument\RolesRid 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\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  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');
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  public function titleQuery() {
    $entities = $this->roleStorage
      ->loadMultiple($this->value);
    $titles = [];
    foreach ($entities as $entity) {
      $titles[] = $entity
        ->label();
    }
    return $titles;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RolesRid::$roleStorage protected property The role entity storage.
RolesRid::create public static function
RolesRid::titleQuery public function
RolesRid::__construct public function Constructs a \Drupal\user\Plugin\views\argument\RolesRid object.