How to filter nodes on a view based on user role shared by both nodes authors and current user? Working on Drupal 8.9.1
I need to list nodes with Views and filter them based on user role shared by both nodes authors and current user.
If I add a relationship to content author and a contextual filter on (author)User ID with default provided by logged user ID, I only get nodes authored by the current user.
Let's say we have a role &quot;Staff A&quot;, I need any user with this role to be able to see any nodes from any users with the same role &quot;Staff A&quot;.
Thanks for any tip here.
Finally, using role as contextual filter was not a good choice. It is working now but with a different option.
Using a term reference field for both user and node with the same vocabulary was my solution.
In my example, let's say I have a taxonomy field called Staff (field_staff), related to a vocabulary called Staff too.
I have added this field to user account and content type (the one(s) I need in Views).
Then, within my View, I have added two relationships:
Content using field_staff and
User using field_staff with a relationship to the previous relationship (reverse__user__field_staff).
Finally, I have added a contextual filter on User ID provided by default (logged in user) and with a relationship to User using field_staff.
And voilà, the view is listing any nodes filtered by field_staff equal to the current user field_staff.
Hope this helps.