Skip to content

Instantly share code, notes, and snippets.

@keopx
Last active January 24, 2017 18:22
Show Gist options
  • Save keopx/c714f5f40e775b8ec251257874ae80d6 to your computer and use it in GitHub Desktop.
Save keopx/c714f5f40e775b8ec251257874ae80d6 to your computer and use it in GitHub Desktop.
Drupal 8 Group - Create a view : Contents of groups the user is registered

Drupal 8 Group - Create a view : Contents of groups the user is registered

I've had a similar problem where I needed to show groups in which the current user is a member of and nodes that reference those groups (2 views). I started off from the wrong side but then I changed the view and started off from Group Content. So try like this:

  • Create a new view and set the content of the view to be Group content
  • Add a relationship to Group (The group containing the entity.) so you will get the Group title etc
  • Add a relationship to Group content for User (Relates to the group content entities that represent the User.) so you will get the Groups of the current user
  • Add a contextual filter User ID and when the filter value is not available set the default value to User ID from logged in user and the relationship should be the Group content for User

Now you can add a field Title and set the relationship on the Group and you should get a list of groups the user is a member of. After that, it's just a matter of setting different relationships to the content you would like to show. I hope this will help your case.

Reference: https://www.drupal.org/node/2793631#comment-11613765

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment