Views does not follow view option of `hook_node_access`. Use `Nodeaccess` mod...

Contribution Date
Technology
Contribution Project
Contribution Details

Views does not follow view option of `hook_node_access`. Use `Nodeaccess` module if you want to control nodes listing in views as well. You can also use something as below for quick fix with VAPN:

/** * Implements hook_views_pre_render(). */ function example_views_pre_render(ViewExecutable $view) { $user = \Drupal::currentUser(); $vapn_config = \Drupal::service('config.factory')->get('vapn.vapnconfig'); $vapn_node_types = $vapn_config->get('vapn_node_list'); foreach ($view->result as $key => $row) { if ($row->_entity) { $is_vapn_bundle = FALSE; if ($bundle = $row->_entity->bundle()) { $is_vapn_bundle = in_array($bundle, $vapn_node_types); } if (!$row->_entity->access('view', $user) && !$view->query->options['disable_sql_rewrite'] && $is_vapn_bundle) { unset($view->result[$key]); } } } }

It will automatically apply access to the views containing VAPN nodes. If you want to show all nodes in a view irrespective of VAPN permissions, just use `Disable Sql Rewrite` in Query settings.

Contribution Author
Files count
0
Patches count
0