I want to create a block view in the user page, listing all groups that user belong to.
So, I want to use the UID in the URL as contextual filter.

Also, I have two group types: public groups and private groups.

If the actual user is viewing his own profile, list all groups the user belongs
If is another user viewing the profile, list all public groups the user belongs

I tried to make a relationship in a View of Groups, but the only option is the Group Creator

Can anyone help me create other relationships for groups view?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

victorcpereira created an issue. See original summary.

JulienD’s picture

Subscribing.

I'm looking for the same thing and also to display all contents saved in groups the user have access. After playing with views Arguments and Contextual Filters I have not been able to make it work.

just_like_good_vibes’s picture

there is a solution proposed here :
https://www.drupal.org/node/2793631#comment-11613765

markconroy’s picture

Hi Guys,

I have created a patch that adds a view to the group module to list the groups the currently logged in user is a member of.

I'll attach it here as a patch to be considered for the module, and also as a config file in case someone just wants to import it to a current project (in which case, rename the file to views.view.group_mine.yml - I'm not sure why Drupal.org added the extra underscore).

Status: Needs review » Needs work

The last submitted patch, 4: my-groups-view-2829632-4.patch, failed testing.

markconroy’s picture

Category: Support request » Feature request
markconroy’s picture

Just adding a blank line to the end of the patch file - I think that's why it's failing the tests.

Status: Needs review » Needs work

The last submitted patch, 7: my-groups-view-2829632-7.patch, failed testing.

andrewmacpherson’s picture

I don't quite understand why the tests fail, but they mention:

Drupal\Core\Entity\EntityStorageException: 'view' entity with ID 'groups_mine' already exists.

In patch #7 I see that the new file is called "views.view.group_mine.yml", however the the ID of the new view (inside the file) is id: groups_mine. In other words, the YML filename is at odds with the config ID it contains. That's worth fixing first.

markconroy’s picture

Status: Needs work » Needs review
FileSize
6.7 KB

Fixing view id.

keopx’s picture

Status: Needs review » Reviewed & tested by the community

Works fine for me.

+1

kristiaanvandeneynde’s picture

Just to let you guys know, since beta5 you can start building a view from the Group table. So perhaps this should be reworked to start from that table instead. Unless this is a patch that we do not want in Group, but as a support request answer instead. In which case it is fine as is, but the issue should then be marked as a fixed support request.

foolfitz’s picture

hi, @kristiaanvandeneynde
I'm a newbie of Drupal, I tried to create a view of the group of a user belong to, but not succeeded, following are my steps to create the view:

  • add a view, VIEW SETTINGS:show "Group", and "Create a block"
  • add a Relationship: User
  • add a Contextual Filter: Group creator
    { When The Filter Value is not Available: Display contents of "No results found"}

I didn't set other options.
Can you tell me how to just use Views to display the groups of a user belong to? thank you so much!

kristiaanvandeneynde’s picture

@foolfitz, you added a relationship to the group creator.

Instead you need to:
Relate to Group content (filtering on group_membership)
Relate to User from Group content

foolfitz’s picture

@kristiaanvandeneynde
sorry, it is still not work for me,
I don't know what I did wrong :(

kristiaanvandeneynde’s picture

FileSize
5.12 KB

Use this as a start, it's the most basic version that you can then expand upon.

taitai’s picture

FileSize
6.09 KB

Here is another version which displays all the groups that belong to the current logged in user

kristiaanvandeneynde’s picture

          group_content_plugins:
            group_membership: group_membership
            'group_node:article': '0'
            'group_node:group_document': '0'
            'group_node:page': '0'

When exporting a view like this, you should only list those plugins that are enabled (i.e.: not zero). It's safe and even recommended to remove the bottom 3 entries.

dang42’s picture

I applied the patch in #10 and it applied without error.

I can see the .yml file in /modules/contrib/group/config/optional/, but I don't see it in the list of views.

I also tried downloading the .txt file @taitai included, renaming it to views.view.my_groups.yml - also nothing in the UI.

What am I doing wrong? I cannot figure out how to build this on my own, so I'm going to need some guidance here.

Thanks!
DanG

kristiaanvandeneynde’s picture

When it's in the optional map and the module is already enabled it won't do anything. That patch needs to have an update hook to make existing sites receive the view or you need to import it manually under Config > Single Import

dang42’s picture

@kristiaanvandeneynde

Ahh, that makes perfect sense. Still getting used to how D8 works... :)

I got both of the example views imported and working.

Thanks!

foolfitz’s picture

Excuse me, how could I use the view files from #16 and #17?
Should I import it at somewhere?

taitai’s picture

foolfitz - Go to Configuration->Configuration Synchronization and choose import.
You will need to prepare a file with the contents of #16 or #17 before hand.

thomas.lie’s picture

thank you @taitai

I used your solution #17 and combine it with my View
Got mine works finally!

I've been pulling my hair out :)

foolfitz’s picture

FileSize
74.77 KB

@taitai: thank you for the reply, but the import failed:
import error

CocoLeBo’s picture

I am looking to do this in Group v7, does anyone know if there is a solution / patch?

CocoLeBo’s picture

As for the initial Question "How can I create a view listing all groups that a user belong to?"

Works in Group v7.x using

  • "RELATIONSHIPS" Group:Group membership
  • "CONTEXTUAL FILTERS" Group:Group membership - Provide default value: User ID from logged in user.
kristiaanvandeneynde’s picture

Category: Feature request » Support request
Status: Reviewed & tested by the community » Fixed

This seems to have turned into a support request for which there is an answer.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dercheffe’s picture

@taitai you made my day after hours of research, thank you very very much :)

leofishman’s picture

Thanks a lot @tatai

Rafi Afridi’s picture

great

themaurice’s picture

There also a solution :

Relationships
Group content : filter by plugin > Group membership
Group content user

Contextaul filters
User:User ID
WHEN THE FILTER VALUE IS NOT IN THE URL > User ID from logged in user

Tested it's work.

thidd’s picture

FileSize
7.53 KB

I have this way to create a view and make the list of user group as this path:
/user/%user/my-groups
Please check if it need to improve anythings else.

kscheirer’s picture

@https://www.drupal.org/u/mrddthi

Can you open a new issue and add your view as a patch to the group module? I think it is useful, and a sensible default for the module to provide.

monaw’s picture

Component: Group (group) » Code

i'm looking for a way to do this with the new Group 3 module, anybody else have a solution?

naveenvalecha’s picture

Following, I'm seeking for the same in how to achieve it with Group 3

8bitplateau’s picture

FileSize
7.55 KB

Hi, here is a working views block for group 3 that can be placed on a user page.
It shows group relationships, and does some contextual filtering from there.
The end result is a list of links to groups the user belongs to.
It is wise to add a further filter on the type of relationship with the specific group type but that will make this export case-specific.