In Drupal 8, I implemented a hook_node_access
function in my module to control access for a certain role under certain conditions and it works fine.
However, all of that content type are still shown on a view when the user views it. This is expected behavior according to the documentation:
In node listings (lists of nodes generated from a select query, such as the default home page at path 'node', an RSS feed, a recent content block, etc.), ... hook_node_access() is not called on each node for performance reasons and for proper functioning of the pager system. When adding a node listing to your module, be sure to use an entity query, which will add a tag of "node_access". This will allow modules dealing with node access to ensure only nodes to which the user has access are retrieved, through the use of hook_query_TAG_alter(). See the Entity API topic for more information on entity queries.
I understand why the view does not check each individual content, but I do not understand what this documentation is asking me to do to fix that. The documentation for hook_query_TAG_alter
and on entity queries is not very helpful either.
How do I ensure that only items of this content type that the current user has view access to are shown in a view?