Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / user / src / Plugin / views / filter / Current.php
1 <?php
2
3 namespace Drupal\user\Plugin\views\filter;
4
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;
9
10 /**
11  * Filter handler for the current user.
12  *
13  * @ingroup views_filter_handlers
14  *
15  * @ViewsFilter("user_current")
16  */
17 class Current extends BooleanOperator {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
23     parent::init($view, $display, $options);
24
25     $this->value_value = $this->t('Is the logged in user');
26   }
27
28   public function query() {
29     $this->ensureMyTable();
30
31     $field = $this->tableAlias . '.' . $this->realField . ' ';
32     $or = new Condition('OR');
33
34     if (empty($this->value)) {
35       $or->condition($field, '***CURRENT_USER***', '<>');
36       if ($this->accept_null) {
37         $or->isNull($field);
38       }
39     }
40     else {
41       $or->condition($field, '***CURRENT_USER***', '=');
42     }
43     $this->query->addWhere($this->options['group'], $or);
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getCacheContexts() {
50     $contexts = parent::getCacheContexts();
51
52     // This filter depends on the current user.
53     $contexts[] = 'user';
54
55     return $contexts;
56   }
57
58 }