3 namespace Drupal\node\Plugin\views\filter;
5 use Drupal\Core\Database\Query\Condition;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\views\Plugin\views\filter\FilterPluginBase;
10 * Filter by node_access records.
12 * @ingroup views_filter_handlers
14 * @ViewsFilter("node_access")
16 class Access extends FilterPluginBase {
18 public function adminSummary() {}
19 protected function operatorForm(&$form, FormStateInterface $form_state) {}
20 public function canExpose() {
25 * See _node_access_where_sql() for a non-views query based implementation.
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)
41 $this->query->addWhere('AND', $grants);
42 $this->query->addWhere('AND', $table . '.grant_view', 1, '>=');
49 public function getCacheContexts() {
50 $contexts = parent::getCacheContexts();
52 $contexts[] = 'user.node_grants:view';