3 namespace Drupal\user\Plugin\views\filter;
5 use Drupal\Core\Database\Query\Condition;
6 use Drupal\views\Plugin\views\display\DisplayPluginBase;
7 use Drupal\views\ViewExecutable;
8 use Drupal\views\Plugin\views\filter\BooleanOperator;
11 * Filter handler for the current user.
13 * @ingroup views_filter_handlers
15 * @ViewsFilter("user_current")
17 class Current extends BooleanOperator {
22 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
23 parent::init($view, $display, $options);
25 $this->value_value = $this->t('Is the logged in user');
28 public function query() {
29 $this->ensureMyTable();
31 $field = $this->tableAlias . '.' . $this->realField . ' ';
32 $or = new Condition('OR');
34 if (empty($this->value)) {
35 $or->condition($field, '***CURRENT_USER***', '<>');
36 if ($this->accept_null) {
41 $or->condition($field, '***CURRENT_USER***', '=');
43 $this->query->addWhere($this->options['group'], $or);
49 public function getCacheContexts() {
50 $contexts = parent::getCacheContexts();
52 // This filter depends on the current user.