Exclude specific nodes from a view based on role permissions I am using View access per node to hide certain nodes from the general public and allow specific roles to view it, which is simple and works like a charm.
The issue is that those nodes are shown, even when browsing with anonymous user. I can't find a way for the view to identify the &quot;View access per node&quot; status for each row.
I thought to change my approach; I was looking through the Comparison and Overview of Access Control modules, but any non-deprecated option available in Drupal 8 seems an overkill for this case.
Views does not respect hook_node_access which is what this module uses. Module creator should've used hook_node_access_records along with hook_node_grants instead.
You could try comment #3 as a workaround.

/**
 * Implements hook_views_pre_render().
 */
function example_views_pre_render(ViewExecutable $view) {
  $user = \Drupal::currentUser();
  $vapn_config = \Drupal::service('config.factory')-&gt;get('vapn.vapnconfig');
  $vapn_node_types = $vapn_config-&gt;get('vapn_node_list');

  foreach ($view-&gt;result as $key =&gt; $row) {
    if ($row-&gt;_entity) {
      $is_vapn_bundle = FALSE;
      if ($bundle = $row-&gt;_entity-&gt;bundle()) {
        $is_vapn_bundle = in_array($bundle, $vapn_node_types);
      }

      if (!$row-&gt;_entity-&gt;access('view', $user) &amp;&amp; !$view-&gt;query-&gt;options['disable_sql_rewrite'] &amp;&amp; $is_vapn_bundle) {
        unset($view-&gt;result[$key]);
      }
    }
  }
}

credit: ash2303