Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comment | File | Size | Author |
---|---|---|---|
#38 | my_groups.yml | 7.55 KB | 8bitplateau |
#4 | my-groups-view-2829632-4.patch | 6.69 KB | markconroy |
#4 | views.view_.group_mine.yml | 6.24 KB | markconroy |
#7 | my-groups-view-2829632-7.patch | 6.7 KB | markconroy |
#10 | my-groups-view-2829632-10.patch | 6.7 KB | markconroy |
|
Comments
Comment #2
JulienD CreditAttribution: JulienD as a volunteer commentedSubscribing.
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.
Comment #3
just_like_good_vibesthere is a solution proposed here :
https://www.drupal.org/node/2793631#comment-11613765
Comment #4
markconroy CreditAttribution: markconroy as a volunteer and at Annertech for Trinity College Dublin commentedHi 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).
Comment #6
markconroy CreditAttribution: markconroy as a volunteer and at Annertech for Trinity College Dublin commentedComment #7
markconroy CreditAttribution: markconroy as a volunteer and at Annertech for Trinity College Dublin commentedJust adding a blank line to the end of the patch file - I think that's why it's failing the tests.
Comment #9
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commentedI don't quite understand why the tests fail, but they mention:
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.Comment #10
markconroy CreditAttribution: markconroy as a volunteer and at Annertech for Trinity College Dublin commentedFixing view id.
Comment #11
keopxWorks fine for me.
+1
Comment #12
kristiaanvandeneyndeJust 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.
Comment #13
foolfitz CreditAttribution: foolfitz commentedhi, @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:
{ 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!
Comment #14
kristiaanvandeneynde@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
Comment #15
foolfitz CreditAttribution: foolfitz commented@kristiaanvandeneynde
sorry, it is still not work for me,
I don't know what I did wrong :(
Comment #16
kristiaanvandeneyndeUse this as a start, it's the most basic version that you can then expand upon.
Comment #17
taitai CreditAttribution: taitai as a volunteer commentedHere is another version which displays all the groups that belong to the current logged in user
Comment #18
kristiaanvandeneyndeWhen 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.
Comment #19
dang42 CreditAttribution: dang42 as a volunteer commentedI 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
Comment #20
kristiaanvandeneyndeWhen 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
Comment #21
dang42 CreditAttribution: dang42 as a volunteer commented@kristiaanvandeneynde
Ahh, that makes perfect sense. Still getting used to how D8 works... :)
I got both of the example views imported and working.
Thanks!
Comment #22
foolfitz CreditAttribution: foolfitz commentedExcuse me, how could I use the view files from #16 and #17?
Should I import it at somewhere?
Comment #23
taitai CreditAttribution: taitai as a volunteer commentedfoolfitz - Go to Configuration->Configuration Synchronization and choose import.
You will need to prepare a file with the contents of #16 or #17 before hand.
Comment #24
thomas.lie CreditAttribution: thomas.lie commentedthank you @taitai
I used your solution #17 and combine it with my View
Got mine works finally!
I've been pulling my hair out :)
Comment #25
foolfitz CreditAttribution: foolfitz commented@taitai: thank you for the reply, but the import failed:
Comment #26
CocoLeBo CreditAttribution: CocoLeBo commentedI am looking to do this in Group v7, does anyone know if there is a solution / patch?
Comment #27
CocoLeBo CreditAttribution: CocoLeBo commentedAs for the initial Question "How can I create a view listing all groups that a user belong to?"
Works in Group v7.x using
Comment #28
kristiaanvandeneyndeThis seems to have turned into a support request for which there is an answer.
Comment #30
dercheffe@taitai you made my day after hours of research, thank you very very much :)
Comment #31
leofishman CreditAttribution: leofishman commentedThanks a lot @tatai
Comment #32
Rafi Afridi CreditAttribution: Rafi Afridi commentedgreat
Comment #33
themaurice CreditAttribution: themaurice as a volunteer commentedThere 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.
Comment #34
thidd CreditAttribution: thidd as a volunteer commentedI 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.
Comment #35
kscheirer@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.
Comment #36
monaw CreditAttribution: monaw commentedi'm looking for a way to do this with the new Group 3 module, anybody else have a solution?
Comment #37
naveenvalechaFollowing, I'm seeking for the same in how to achieve it with Group 3
Comment #38
8bitplateau CreditAttribution: 8bitplateau commentedHi, 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.