5

I've used Organic Groups for the past 6 months and found it to complex for my simple use case. Creating even basic views to show users of a group or content of a group turns quickly into "rocket since".

The module comes with a ton of extra functionality that I didn't need, like access control.

Plus I couldn't migrate my group content and group membership and when I manually inserted into the tables it wouldn't work reliably.

Below is my solution to create basic OG features with flag and reference modules. My requirements were:

  1. users can create groups
  2. users can join groups (and leave them) without approvals or permissions
  3. users can add other nodes to show up as group content
  4. use views to display group content and group membership

Please post your comments or alternative solutions.

Btw, Clive encouraged me on meta to post this how-to. Thanks, Clive!

10

1. Users can create groups:

To create groups you just create a new content type "groups" and with permissions for users to create new content. I also added an image field to allow uploading a group logo.

2. Users can join groups (and leave them) without approvals or permissions

The Flag module turned out to be an excellent way to allow users to join (and leave) groups. Create a new flag called "groups" and make sure the "global flag" is unchecked and then select your "groups" as "flaggable content". You can also customize the flag links to say "join this group", etc. Btw, just changing the default link text is hard in OG.

3. Users can add other nodes to show up as group content

To assign other nodes to the "groups" content type I used node references from the references module. I also looked at (and used before) entity references and DA members seem to prefer entity references.

Node references however has more installs and comes with a nifty "References" feature that allowed me to filter the "available groups" on a node add/edit page to only the groups that have been flagged by the user.

To allow my photo nodes to be assigned to the groups type I add a "group_content" field to the photo type and select "node reference" as the field type. You can specify the widget type (autocomplete, checkbox, select list), I picked checkbox and 5 as the "number of values". For "content that can be referenced" you simply select your "groups" content type.

With this setting you can create a new photo node and assign it to ANY of the groups that have been created so far. To limit it to a user's groups you create a view for "content of type = group" and then add relationship "Flags: Node flag" with the setting "include only flagged content" checked. Select your "group flag" and select "current user".

Now your view only shows groups flagged by the current user. Click "Add" below "Displays" and select "References", then save.

Now edit your photo content type again and edit the "group_content" field. At the bottom you there is an option for "The list of nodes that can be referenced can be provided by a view" and you should see your new view as an option. Select that and save.

You can create similar references from other nodes by using "add existing field" in "manage fields" of the content type.

4. Use views to display group content and group membership

Now all that is left is creating some views. For example, I want to show a list of users and a list of group content on a group page.

In OG these views are complex, see an example of group content view and users of a group.

With Flags and Node References they are very simple:

List of groups with number of users in each group":

  • content type = group
  • add relationship "flags: node counter" with "groups" selected and "include flagged content" not selected
  • add field "Flags: Flag counter", that shows the number of users
  • display in a table and enable default sort by title or number of users. Done

List of members that belong to a group:

  • create a view of users
  • add relationship "Flags: User's flagged content" with "include only users who have flagged content" checked and "group" as "flagged"
  • add contextual filter for "Flags: content id" and provide a default value of "content ID from URL"
  • create a block view to show the first 5 users with a more link to show all users on a page. Select that block to show up for your "group" content type

Show list of nodes that are assigned to a group:

  • create a view with content type = photo for example
  • add contextual filter "Content: Groups (field_group_content) - that's the node reference field we created above. Select "content from URL" as the default value and now you'll only see photos assigned to the current group.
  • create a block to show the most recent 5 with a "more" link to a page showing all. Then enable the block to show for type "group".

That's it. As an additional benefit I could import my legacy group membership and group content with a couple of basic SQL INSERT statements.

  • I just wanted to 1) thank you for the detailed explanation, and 2) explain that both can probably be true at the same time -- you can use OG in conjunction with your method. In my case, I can see use cases for both. Thanks! – Dizzle McShizzle Feb 17 '15 at 21:30
0

There is a new kid in town these days (starting from D7), which offers a potential alternative to the Organic groups module, i.e. the Group module (current maintainance of it happens around where Dries started Drupal ...). Here is a quote from its project page:

This module is designed to be an alternative to Organic groups (OG).

Some more details about it (also from its project page):

Organic Groups allows content itself to be groups, which isn't always what people want. It relies on an entity reference field to keep track of the ties between a group (node, term, ...) and its content (node, term, user, ...).

Groups instead creates groups as entities, making them fully fieldable, extensible and exportable. Every group can have users, roles and permissions attached to it. Groups can also act as a parent of any type of entity. Seeing as a group itself is also an entity, creating subgroups is very easy.

Even though it only has a beta release for D7 so far, its Usage statistics seem to indicate it is like a "rising star". And I've heard it mentioned recently in various occasions as a valid alternative for the "heavy" Organic groups module.

Additional sub-modules

Extra features can be enabled via these sub-modules:

  • Group Add: Add members to a group without their consent.
  • Subgroup: Make group to belong to another group.
  • Group Invite: Allow group members to invite people into their group.
  • Group Node: Enables Group functionality for the Node module.
  • Group member profiles: Create multiple fieldable member profiles, which can be attached to a member.

Integration with Rules

The Group module also integrate nicely with the Rules module, as explained in comment #2 of issue 2603136, which states the following:

... you can already use Rules to:

  • Add a new Group
  • Create a new GroupMembership and save it (the equivalent of $group->addMember())
  • Add or remove a GroupRole from a GroupType
  • React on new GroupMembership or Group entities

What hasn't been done yet is custom Rules actions or conditions. Seeing as 90%+ of Group is pure Entity API CRUD-operations, there has been no custom Rules code yet given how much you can already accomplish out-of-the-box.

Useful Rules we may add could be:

  • E-mail all members of a Group, optionally filtered by GroupRole
  • Easier-to-understand labels for the above list: "Member joined group" sounds easier than "GroupMembership entity is created"

...

Integrations with other modules

Refer to Integrations with other modules and its "Related issues" about other modules for which integrations already exist, or are in the pipeline.

Example of using the Group module

Refer to How to implement an option for users to limit access to nodes/comments to users with the same role while posting it? for an interesting illustration of how this module can be used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.