X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Fsrc%2FPlugin%2Fviews%2Fargument%2FUserUid.php;fp=web%2Fcore%2Fmodules%2Fcomment%2Fsrc%2FPlugin%2Fviews%2Fargument%2FUserUid.php;h=69621559c4cac66393c3425c0cfd119cf7860fd3;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/comment/src/Plugin/views/argument/UserUid.php b/web/core/modules/comment/src/Plugin/views/argument/UserUid.php new file mode 100644 index 000000000..69621559c --- /dev/null +++ b/web/core/modules/comment/src/Plugin/views/argument/UserUid.php @@ -0,0 +1,108 @@ +database = $database; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static($configuration, $plugin_id, $plugin_definition, $container->get('database')); + } + + public function title() { + if (!$this->argument) { + $title = \Drupal::config('user.settings')->get('anonymous'); + } + else { + $title = $this->database->query('SELECT name FROM {users_field_data} WHERE uid = :uid AND default_langcode = 1', [':uid' => $this->argument])->fetchField(); + } + if (empty($title)) { + return $this->t('No user'); + } + + return $title; + } + + protected function defaultActions($which = NULL) { + // Disallow summary views on this argument. + if (!$which) { + $actions = parent::defaultActions(); + unset($actions['summary asc']); + unset($actions['summary desc']); + return $actions; + } + + if ($which != 'summary asc' && $which != 'summary desc') { + return parent::defaultActions($which); + } + } + + public function query($group_by = FALSE) { + $this->ensureMyTable(); + + // Use the table definition to correctly add this user ID condition. + if ($this->table != 'comment_field_data') { + $subselect = $this->database->select('comment_field_data', 'c'); + $subselect->addField('c', 'cid'); + $subselect->condition('c.uid', $this->argument); + + $entity_id = $this->definition['entity_id']; + $entity_type = $this->definition['entity_type']; + $subselect->where("c.entity_id = $this->tableAlias.$entity_id"); + $subselect->condition('c.entity_type', $entity_type); + + $condition = db_or() + ->condition("$this->tableAlias.uid", $this->argument, '=') + ->exists($subselect); + + $this->query->addWhere(0, $condition); + } + } + + /** + * {@inheritdoc} + */ + public function getSortName() { + return $this->t('Numerical', [], ['context' => 'Sort order']); + } + +}