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