View source
<?php
namespace Drupal\comment\Plugin\views\argument;
use Drupal\Core\Database\Connection;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class UserUid extends ArgumentPluginBase {
protected $database;
public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->database = $database;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('database'));
}
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', array(
':uid' => $this->argument,
))
->fetchField();
}
if (empty($title)) {
return $this
->t('No user');
}
return $title;
}
protected function defaultActions($which = NULL) {
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();
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);
}
}
public function getSortName() {
return $this
->t('Numerical', array(), array(
'context' => 'Sort order',
));
}
}