See _node_access_where_sql() for a non-views query based implementation.
Overrides FilterPluginBase::query
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
->addWhere('AND', $grants);
$this->query
->addWhere('AND', $table . '.grant_view', 1, '>=');
}
}