You are here

class Uid in Drupal 10

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

Argument handler to accept a user id.

Plugin annotation

@ViewsArgument("user_uid");

Hierarchy

  • class \Drupal\views\Plugin\views\argument\NumericArgument extends \Drupal\views\Plugin\views\argument\ArgumentPluginBase
    • class \Drupal\user\Plugin\views\argument\Uid

Expanded class hierarchy of Uid

1 file declares its use of Uid
UidRevision.php in core/modules/node/src/Plugin/views/argument/UidRevision.php
2 string references to 'Uid'
tracker_views_data in core/modules/tracker/tracker.views.inc
Implements hook_views_data().
views.view.test_field_permission.yml in core/modules/user/tests/modules/user_test_views/test_views/views.view.test_field_permission.yml
core/modules/user/tests/modules/user_test_views/test_views/views.view.test_field_permission.yml

File

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

Namespace

Drupal\user\Plugin\views\argument
View source
class Uid extends NumericArgument {

  /**
   * The user storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * Constructs a \Drupal\user\Plugin\views\argument\Uid 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_type.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));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NumericArgument::$value public property The actual value which is used for querying.
NumericArgument::buildOptionsForm public function 1
NumericArgument::defineOptions protected function 1
NumericArgument::getContextDefinition public function
NumericArgument::getSortName public function
NumericArgument::query public function 1
NumericArgument::title public function 2
Uid::$storage protected property The user storage.
Uid::create public static function
Uid::titleQuery public function Override the behavior of title(). Get the name of the user. Overrides NumericArgument::titleQuery
Uid::__construct public function Constructs a \Drupal\user\Plugin\views\argument\Uid object.