3 namespace Drupal\user\Plugin\views\filter;
5 use Drupal\views\Plugin\views\display\DisplayPluginBase;
6 use Drupal\views\ViewExecutable;
7 use Drupal\views\Plugin\views\filter\BooleanOperator;
10 * Filter handler for the current user.
12 * @ingroup views_filter_handlers
14 * @ViewsFilter("user_current")
16 class Current extends BooleanOperator {
21 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
22 parent::init($view, $display, $options);
24 $this->value_value = $this->t('Is the logged in user');
27 public function query() {
28 $this->ensureMyTable();
30 $field = $this->tableAlias . '.' . $this->realField . ' ';
33 if (empty($this->value)) {
34 $or->condition($field, '***CURRENT_USER***', '<>');
35 if ($this->accept_null) {
40 $or->condition($field, '***CURRENT_USER***', '=');
42 $this->query->addWhere($this->options['group'], $or);
48 public function getCacheContexts() {
49 $contexts = parent::getCacheContexts();
51 // This filter depends on the current user.