71e8e95e5aace600236c082b03ed7ee940ea2271
[yaffs-website] / web / core / modules / node / src / Plugin / views / filter / Access.php
1 <?php
2
3 namespace Drupal\node\Plugin\views\filter;
4
5 use Drupal\Core\Database\Query\Condition;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\views\Plugin\views\filter\FilterPluginBase;
8
9 /**
10  * Filter by node_access records.
11  *
12  * @ingroup views_filter_handlers
13  *
14  * @ViewsFilter("node_access")
15  */
16 class Access extends FilterPluginBase {
17
18   public function adminSummary() {}
19   protected function operatorForm(&$form, FormStateInterface $form_state) {}
20   public function canExpose() {
21     return FALSE;
22   }
23
24   /**
25    * See _node_access_where_sql() for a non-views query based implementation.
26    */
27   public function query() {
28     $account = $this->view->getUser();
29     if (!$account->hasPermission('bypass node access')) {
30       $table = $this->ensureMyTable();
31       $grants = new Condition('OR');
32       foreach (node_access_grants('view', $account) as $realm => $gids) {
33         foreach ($gids as $gid) {
34           $grants->condition((new Condition('AND'))
35             ->condition($table . '.gid', $gid)
36             ->condition($table . '.realm', $realm)
37           );
38         }
39       }
40
41       $this->query->addWhere('AND', $grants);
42       $this->query->addWhere('AND', $table . '.grant_view', 1, '>=');
43     }
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getCacheContexts() {
50     $contexts = parent::getCacheContexts();
51
52     $contexts[] = 'user.node_grants:view';
53
54     return $contexts;
55   }
56
57 }