Problem/Motivation

When I'm listing nodes then I see all node including access restricted nodes.
I would like list only nodes with access.

Steps to reproduce

Enable group, gnode.
Create a group, enable gnode for page.
Go to group/%group/nodes
Create a new node. Relation automatically created.
Not I see the new node in the list.

Create custom module.

function hook_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if($entity instanceof NodeInterface){ return AccessResult::forbidden(); }
}

Now the user can't view the Node.
But the group/%group/nodes still shows it.

Proposed resolution

Is it possible to extend the view to show only the accessed nodes?

Why I want to do this?

Actually the group has a permission view group_node:page entity.
It works well, but I want to extend the view permission with custom code.

I want to create a custom permission like this: view group_node:page entity only men
When a group_member check the group/%group/nodes then I would like to check a field inside the group_membership (gender) to access to the node.

Comments

kecsot created an issue. See original summary.

kecsot’s picture

Found an answer. But there is no better solution?

https://www.drupal.org/docs/contributed-modules/group/extending-groups-a...

kecsot’s picture

Status: Active » Closed (works as designed)
Issue tags: -

Closed.

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...

function hook_entity_access
Note that this hook is not called for listings (e.g., from entity queries and Views). For nodes, see Node access rights for a full explanation. For other entity types, see hook_query_TAG_alter().