You are here

public function Access::query in Views (for Drupal 7) 8.3

See _node_access_where_sql() for a non-views query based implementation.

Overrides FilterPluginBase::query

File

lib/Views/node/Plugin/views/filter/Access.php, line 34
Definition of Views\node\Plugin\views\filter\Access.

Class

Access
Filter by node_access records.

Namespace

Views\node\Plugin\views\filter

Code

public function query() {
  if (!user_access('administer nodes')) {
    $table = $this
      ->ensureMyTable();
    $grants = db_or();
    foreach (node_access_grants('view') as $realm => $gids) {
      foreach ($gids as $gid) {
        $grants
          ->condition(db_and()
          ->condition($table . '.gid', $gid)
          ->condition($table . '.realm', $realm));
      }
    }
    $this->query
      ->add_where('AND', $grants);
    $this->query
      ->add_where('AND', $table . '.grant_view', 1, '>=');
  }
}