3 namespace Drupal\node\Plugin\views\filter;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\filter\FilterPluginBase;
9 * Filter by node_access records.
11 * @ingroup views_filter_handlers
13 * @ViewsFilter("node_access")
15 class Access extends FilterPluginBase {
17 public function adminSummary() { }
18 protected function operatorForm(&$form, FormStateInterface $form_state) { }
19 public function canExpose() {
24 * See _node_access_where_sql() for a non-views query based implementation.
26 public function query() {
27 $account = $this->view->getUser();
28 if (!$account->hasPermission('bypass node access')) {
29 $table = $this->ensureMyTable();
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)
40 $this->query->addWhere('AND', $grants);
41 $this->query->addWhere('AND', $table . '.grant_view', 1, '>=');
48 public function getCacheContexts() {
49 $contexts = parent::getCacheContexts();
51 $contexts[] = 'user.node_grants:view';