Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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
20   protected function operatorForm(&$form, FormStateInterface $form_state) {}
21
22   public function canExpose() {
23     return FALSE;
24   }
25
26   /**
27    * See _node_access_where_sql() for a non-views query based implementation.
28    */
29   public function query() {
30     $account = $this->view->getUser();
31     if (!$account->hasPermission('bypass node access')) {
32       $table = $this->ensureMyTable();
33       $grants = new Condition('OR');
34       foreach (node_access_grants('view', $account) as $realm => $gids) {
35         foreach ($gids as $gid) {
36           $grants->condition((new Condition('AND'))
37             ->condition($table . '.gid', $gid)
38             ->condition($table . '.realm', $realm)
39           );
40         }
41       }
42
43       $this->query->addWhere('AND', $grants);
44       $this->query->addWhere('AND', $table . '.grant_view', 1, '>=');
45     }
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function getCacheContexts() {
52     $contexts = parent::getCacheContexts();
53
54     $contexts[] = 'user.node_grants:view';
55
56     return $contexts;
57   }
58
59 }