Original Issue
I'm struggling with OG and views. I want to use this module, but it's becoming more obvious that it may not be possible.
The views integrations make little sense. And because it has apparently changed from Drupal 7, past answers to similar questions are outdated. For example, there is constant reference in past documentation to using relationships that do not seem to be available in Drupal 8, such as "OG group: OG group from Node" and "OG group: OG membership from OG group."
This lack of relationships is where things start to fall apart for me. If I create a "content" view, it's easy to display those groups authored by the user. But there's no clear way of also bringing in groups to which that user is a member.
If I create an 'Og:membership' view, I can, strangely, add a field that shows the ID of the group to which the membership belongs, but there is no field for the title of the group. Nor is there a relationship that can be added to pull in the title. The only relationship available in a og:membership view is 'user'. And bringing that in does not open up any relationship that provides access to the group title.
Even creating a view that simply displays the number of members in a group seems to be impossible.
I guess my point is nothing is clear, and I'm pounding my head against a wall. It looks like the module is abandoned, which sucks, because it seems like it's just on the edge of being production ready. And, in comparison with the Group module, this module is more lightweight and appropriate for my use case.
Updated Issue
Since the original post, there was some views support added. However, we still lack the ability to relate og_memberships to group enabled entities. Which would allow you to create a view of all groups a user is a member of or show the membership counts for a list of group nodes.
Proposed Resolution
Create a views relationship to og_memberships from any group enabled entities.
There was work done on this on github. I'm opening a MR here with that work.
For reference, here is the old github issue/PR:
old gitub issue: https://github.com/Gizra/og/issues/752
old github PRs: https://github.com/Gizra/og/pull/756 and https://github.com/Gizra/og/pull/755
| Comment | File | Size | Author |
|---|
Issue fork og-3306494
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dobe commentedAdd a pull request at github for this issue: https://github.com/Gizra/og/pull/755
Attaching diff so I can use in composer.
Comment #3
loze commentedThis will only work if your groups are nodes. Ive been using the code here which will work for any entity that is enabled as a group
https://github.com/Gizra/og/issues/752
Comment #4
dobe commented@loze create a patch and post it here. Or a pull request at the github, either way it doesn't help if it just a comment it basically got lost when this should be a part of the module.
Comment #5
loze commentedAdded a pull request here
https://github.com/Gizra/og/pull/756
Comment #6
loze commentedComment #8
loze commentedNow that dev moved from GH to here, I created a MR from the work on GH and also updated the original issue.
MR!12 adds views relationships to og_memberships from any group enabled entity types.
This allows you to create a view of all groups a user is a member of or show the membership counts for a list of groups.
Comment #9
claudiu.cristeaThis is a nice addition. Could you, please, add a test to prove it works? Setting to "Needs work" because needs test coverage.
Comment #10
loze commentedThanks @claudiu.cristea. Unfortunately, I have been unable to wrap my head around how to write tests. I've tried on several projects but can't seem to grasp it.
Hopefully someone else interested in this feature can help out with that.
Comment #12
joelpittetI did a related test over here, have a look maybe it can be piggybacked on #3525064: Add views relationship to group entities from og_membership entities
Comment #13
joelpittetComment #14
joelpittetAdded a kernel test that exercises the new logic using
nodeentities. I picked nodes because they’re the most common OG group type and we already haveentity_testcoverage elsewhere, so this gives us a bit of variety.Happy to swap it to
entity_testif you’d prefer uniformity—just let me know.Test bot is green 🤖✅!
Comment #15
joelpittetcrediting
Comment #16
loze commentedthank you for doing this @joelpittet
Comment #17
joelpittetNeed a second pair of eyes to confirm it does what it needs to before committing. So setting to Needs Review.
Comment #19
joelpittetThis just needs to go in :D Thanks for those involved!