How to create basic Organic Groups functionality with flags and references? 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:


users can create groups
users can join groups (and leave them) without approvals or permissions
users can add other nodes to show up as group content
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!
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.