I have been looking for an answer for 3 days with no success.
Looks like this is a common requirement among plenty of Drupal 8 projects with not a single answer accross the internet about how is possible to achieve it.
I, as user id 1, created 2 groups titled: “Basketball” and “Football” of the group type (sports) and then I added some users as members to those two groups…
So I have something similar to:
Group Title: Basketball
Group Members:
-
User A (whatever role)
-
User B (whatever role)
-
User C (whatever role)
-
User D (whatever role)
Group Title: Football
Group Members:
-
User 1 (whatever role)
-
User 2 (whatever role)
-
User 3 (whatever role)
-
User 4 (whatever role)
Now, what I really want to accomplish using views is to show a table with the names of all available members registered at the same group of the current logged user.
So if for example if User D is the current logged in user, I want to show him a table displaying:
-
User A
-
User B
-
User C
-
User D
without showing up the other members from other groups like user 1, user 2…
and for example if User 2 is the current logged in user, I want to show him a table displaying:
-
User 1
-
User 2
-
User 3
-
User 4
without showing up the other members from other groups like user A, user B…
Is that possible, and how?
I have followed this issue: https://www.drupal.org/node/2793631#comment-11613765 but with no success!
And this question How do I show the members in a block, contextually filtered by the currently logged in user? with no direct solution by using only the views UI.
My aim is to create an entity reference views to be called from a entity reference field element inside a webform.
UPDATE: This issue (https://www.drupal.org/project/group/issues/2793631#comment-12808833) has a solution On how to a list of all groups in which the current logged in user is a member.
However, for my requirement I need to show a list of all members that belong to the same group of the logged in user… so I did:
-
Create a page view and set the content of the view to be Group content with a url: /my-friends
-
Add a relationship to Group (The group containing the entity.)
-
Add a relationship to Group content for User (Relates to the group content entities that represent the User.)
-
Add a contextual filter to Group ID and when the filter value is not available set the default value to User ID from logged in user and the relationship is set to the Group content for User.
For the preview of the view, everything looks good and I, the admin, can see my name inside the display table along with all the other member with me inside the group.
However, if i log in as any other member inside this group such as: User 2 and go to the view page and receive a table with the message: no members available.