class Uid

Same name and namespace in other branches
  1. 11.x 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

Expanded class hierarchy of Uid

Related topics

1 file declares its use of Uid
UidRevision.php in core/modules/node/src/Plugin/views/argument/UidRevision.php
209 string references to 'Uid'
AreaDisplayLinkTest::setUp in core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php
Comment::query in core/modules/comment/src/Plugin/migrate/source/d6/Comment.php
CommentAccessControlHandler::checkFieldAccess in core/modules/comment/src/CommentAccessControlHandler.php
CommentAnonymousTest::testAnonymous in core/modules/comment/tests/src/Functional/CommentAnonymousTest.php
Tests anonymous comment functionality.
CommentForm::buildEntity in core/modules/comment/src/CommentForm.php
Builds an updated entity object based upon the submitted form values.

... See full list

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));
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.