Views ignore result of custom handler

Created on 8 June 2023, over 1 year ago
Updated 29 June 2023, about 1 year ago

For the project I'm working on, we need the ability to add a checkbox to entities indicating whether or not the entity should be publicly visible to anyone, or only visible to group members. I followed https://www.drupal.org/project/group/issues/3345316 πŸ’¬ Non-group permission within a group? Fixed and https://drupalcamp.be/en/drupal-dev-days-2022/session/reinventing-cores-... and was able to get 99% of the way there. I created a new handler that implements AccessControlInterface, and I'm able to check if the entity is public or private, and from there return AccessResult::allowed(), if needed.

The issue I'm facing is getting views to respect what's returned by the handler. If I have a view that returns a list of nodes (or some other entity), and some of the nodes are part of a group, then nodes that are marked as "Public" should be returned to anonymous users (or users not part of whatever group some of the nodes belong to). Instead, only nodes not part of the group are returned to the anonymous user. The anonymous user can still view public nodes part of a group if they navigate to the URL, but Drupal won't actually show them in the view. Is this the expected behavior? If it is, is there some way I can get views to cooperate?

Steps to reproduce

1. Add a checkbox named "Public" to some content type indicating whether or not the node should be public or private.
2. Add a node to a group, with the checkbox in step 1. selected.
2. Ensure group type permissions are setup so outsiders can't view content.
3. Create a handler implementing AccessControlInterface.
4. Return AccessResult::allowed() if "Public" checkbox is selected.
5. Create a view that lists all nodes of a type, with a mix of nodes part of a group and some not part of a group.
6. Load view as an anonymous user. Nodes part of a group and marked as "Public" should show up in the view, but don't.

πŸ’¬ Support request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Matthew.

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024