- Issue created by @monaw
- πΊπΈUnited States ikphilip Charlotte, NC, USA
I'm currently working through this problem. Although I'm simply trying to output a list of Groups that the User belongs to (via group_membership). There are a few ways to approach this and I think the best solution depends on how you want content rendered by the View.
Fields: Users view
In my opinion the simplest solution to this problem is creating a User view which displays a list of fields. Because this is a User content view the Contextual filters will offer to link User Content by default. Create this contextual filter first for the User ID.
In order to get Group Content fields we need to add two relationships. First add a Category: Group Relationship, Group relationship for User: Relates to the group relationship entities that represent the User. and Filter by Plugin Group membership plugin and Require the Relationship. I've named this "User Group Relationship." Apply and add the second relationship Category: Group Relationship, Group: The group containing the entity. Set it to use your first relationship and Require it. I've named this second relationship "Group" in Administrative title for simplicity since data from this relationship pertains to the Group entity.
Entities: Group view
If your goal is to display group entities then you'll need to create a View which displays Group content. In order to use User as the Contextual Filter first create a Relationship to Group Membership. Create a Relationship find Category: Group, Group Relationship: Relate to the group relationship entities. From there you can relate to the actual grouped entities.. Filter by Plugin Group Membership and Require this relationship. I've named this Relationship "Group Membership."
Now you can add a Contextual Filter based on your Group Relationship. In my settings I wish to specify the User ID in the URL so I select Provide default value and Type: Content ID from URL. Now the numeric ID in your URL can be pulled in to filter on the User ID.
The final thing I've done is ensure that the Group membership relationship only applies to the membership content. Note that in Contextual Filter options we didn't get to specify what content ID so we can theoretically pull in other content/entities with the same numeric ID. I've added this filter to prevent this from happening.
Hope this has been helpful. This isn't the only way I can imagine. You could also try rendering things using Group Membership entities but I think these two examples show the patterns you need to solve this problem.
- πΊπΈUnited States dww
Here's a very simple view based on one I just created for a site I'm building. It's a list of all groups a user belongs to that lives at user/N/groups.
Feel free to modify for your needs.
Enjoy,
-Derek - Status changed to Fixed
11 months ago 1:45am 3 April 2024 - πΊπΈUnited States dww
p.s. Also saving credit for @ikphilip's contribution here.
Automatically closed - issue fixed for 2 weeks with no activity.
- π©πͺGermany vistree
Hi @dww,
can you explain why you use "User ID from route context" as contextual filter - instead of using "Group Ids from current user".
I am still searching for a better group management. If I don't find existing stuff (as a distribution) I will setup all needed views on my own.
And I want to use the best performing approach ;-)