3 namespace Drupal\comment\Plugin\views\argument;
5 use Drupal\Core\Database\Connection;
6 use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
10 * Argument handler to accept a user id to check for nodes that
11 * user posted or commented on.
13 * @ingroup views_argument_handlers
15 * @ViewsArgument("argument_comment_user_uid")
17 class UserUid extends ArgumentPluginBase {
20 * Database Service Object.
22 * @var \Drupal\Core\Database\Connection
27 * Constructs a Drupal\Component\Plugin\PluginBase object.
29 * @param array $configuration
30 * A configuration array containing information about the plugin instance.
31 * @param string $plugin_id
32 * The plugin_id for the plugin instance.
33 * @param mixed $plugin_definition
34 * The plugin implementation definition.
35 * @param \Drupal\Core\Database\Connection $database
36 * Database Service Object.
38 public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database) {
39 parent::__construct($configuration, $plugin_id, $plugin_definition);
41 $this->database = $database;
47 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
48 return new static($configuration, $plugin_id, $plugin_definition, $container->get('database'));
51 public function title() {
52 if (!$this->argument) {
53 $title = \Drupal::config('user.settings')->get('anonymous');
56 $title = $this->database->query('SELECT name FROM {users_field_data} WHERE uid = :uid AND default_langcode = 1', [':uid' => $this->argument])->fetchField();
59 return $this->t('No user');
65 protected function defaultActions($which = NULL) {
66 // Disallow summary views on this argument.
68 $actions = parent::defaultActions();
69 unset($actions['summary asc']);
70 unset($actions['summary desc']);
74 if ($which != 'summary asc' && $which != 'summary desc') {
75 return parent::defaultActions($which);
79 public function query($group_by = FALSE) {
80 $this->ensureMyTable();
82 // Use the table definition to correctly add this user ID condition.
83 if ($this->table != 'comment_field_data') {
84 $subselect = $this->database->select('comment_field_data', 'c');
85 $subselect->addField('c', 'cid');
86 $subselect->condition('c.uid', $this->argument);
88 $entity_id = $this->definition['entity_id'];
89 $entity_type = $this->definition['entity_type'];
90 $subselect->where("c.entity_id = $this->tableAlias.$entity_id");
91 $subselect->condition('c.entity_type', $entity_type);
94 ->condition("$this->tableAlias.uid", $this->argument, '=')
97 $this->query->addWhere(0, $condition);
104 public function getSortName() {
105 return $this->t('Numerical', [], ['context' => 'Sort order']);