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() {}
20 protected function operatorForm(&$form, FormStateInterface $form_state) {}
22 public function canExpose() {
27 * See _node_access_where_sql() for a non-views query based implementation.
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)
43 $this->query->addWhere('AND', $grants);
44 $this->query->addWhere('AND', $table . '.grant_view', 1, '>=');
51 public function getCacheContexts() {
52 $contexts = parent::getCacheContexts();
54 $contexts[] = 'user.node_grants:view';