OG 7.2 View of a User's Groups

Events happening in the community are now at Drupal community events on www.drupal.org.
Anonymous's picture

I am struggling to build a simple view of a user's groups to be displayed on their profile page. This was fairly straightforward with 7.1 but I can't seem to get the view configured with 7.2. I just want to display a list of the group titles that represent the user's subscribed groups.

Ideas welcome.

I can't find the right relationship to allow a contextual filter based on the UID, which I assume needs to be passed to the view to determine the user's groups.

Comments

OG Extras

deastlack's picture

OG Extras is a supplemental module for OG 7.2. It includes a view which will provide a model for creating the view you need, if it doesn't fit the bill directly. I've used it for an OG based collaboration interface I'm currently building. needed minot mods to do what I needed, but th mods were easy.

OG Extras didn't include this view

trainingcity's picture

I installed Extras some time ago, but it did not include the view I need. I need to simply display a list of all the groups a user belongs to on the user's profile page.

This was a simple setup in 7.1. The View was a snap to create. I have the UID of the user in the URL, but there does not seem to be any way make this happen with OG 7.2 and Views.

Suggestions welcome!

Here's one that works for me

chiebert's picture

The gist is that you create a view based on og memberships, then add a relationship 'og membership: group node from og membership', then a contextual filter (don't use a relationship) 'og membership: entity id' with a default value of 'user id from logged-in user' (or user id from URL, if that's how you want to use it), and finally, add some filters like og membership entity type = user, og membership status = active, and (using the group node from membership relationship) content: published = yes.

Here's an attempt at pasting the export:

$view = new view();
$view->name = 'og_user_groups';
$view->description = 'Show groups of a user.';
$view->tag = 'og';
$view->base_table = 'og_membership';
$view->human_name = 'OG User groups';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
  'state' => 'state',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'state' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
);
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['content'] = 'User is not a member of any group.';
/* Relationship: OG membership: Group Node from OG membership */
$handler->display->display_options['relationships']['og_membership_related_node_group']['id'] = 'og_membership_related_node_group';
$handler->display->display_options['relationships']['og_membership_related_node_group']['table'] = 'og_membership';
$handler->display->display_options['relationships']['og_membership_related_node_group']['field'] = 'og_membership_related_node_group';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['title']['label'] = 'Group';
$handler->display->display_options['fields']['title']['hide_alter_empty'] = FALSE;
/* Field: OG membership: Created */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'og_membership';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['label'] = 'Member since';
$handler->display->display_options['fields']['created']['hide_alter_empty'] = FALSE;
$handler->display->display_options['fields']['created']['date_format'] = 'time ago';
/* Sort criterion: Content: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'node';
$handler->display->display_options['sorts']['title']['field'] = 'title';
$handler->display->display_options['sorts']['title']['relationship'] = 'og_membership_related_node_group';
/* Contextual filter: We pass the user ID as the Entity ID. */
$handler->display->display_options['arguments']['etid']['id'] = 'etid';
$handler->display->display_options['arguments']['etid']['table'] = 'og_membership';
$handler->display->display_options['arguments']['etid']['field'] = 'etid';
$handler->display->display_options['arguments']['etid']['ui_name'] = 'We pass the user ID as the Entity ID.';
$handler->display->display_options['arguments']['etid']['default_action'] = 'default';
$handler->display->display_options['arguments']['etid']['title_enable'] = TRUE;
$handler->display->display_options['arguments']['etid']['title'] = '%1 groups';
$handler->display->display_options['arguments']['etid']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['etid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['etid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['etid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['etid']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['etid']['validate']['type'] = 'user';
/* Filter criterion: OG membership: State */
$handler->display->display_options['filters']['state']['id'] = 'state';
$handler->display->display_options['filters']['state']['table'] = 'og_membership';
$handler->display->display_options['filters']['state']['field'] = 'state';
$handler->display->display_options['filters']['state']['relationship'] = 'og_membership';
$handler->display->display_options['filters']['state']['value'] = array(
  1 => '1',
);
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['filters']['status']['value'] = '1';
/* Filter criterion: OG membership: Entity_type */
$handler->display->display_options['filters']['entity_type']['id'] = 'entity_type';
$handler->display->display_options['filters']['entity_type']['table'] = 'og_membership';
$handler->display->display_options['filters']['entity_type']['field'] = 'entity_type';
$handler->display->display_options['filters']['entity_type']['value'] = 'user';

/* Display: Content pane */
$handler = $view->new_display('panel_pane', 'Content pane', 'panel_pane_1');
$handler->display->display_options['argument_input'] = array(
  'etid' => array(
    'type' => 'context',
    'context' => 'entity:user.uid',
    'context_optional' => 0,
    'panel' => '0',
    'fixed' => '',
    'label' => 'We pass to the "Entity ID" the User ID.',
  ),
);

Field of related node table?!?

danielnolde's picture

So far so good, but what about adding e.g. title of the og group node via a views relation "OG membership: Group Node from OG membership"? When creating a relationship to the node table/entities this way in views 3.7, this related table's fields are not available for adding to the view. Very strange, i'm really wondering whether this is due to missing views data definitions of og or a new bug introduced in views. Therefore i'm also not really sure what issue queue to post this into.
Can anybody reproduce this strange missing of a node relation's fields in a view with base table og_membership?

Instructions to create a view for own groups

jukka792's picture

Has anyone done a view which shows current users Groups (groups where user has approved membership)
I am not able to produce a view which would show user groups. I can only produce view which shows all the groups in the system, but users really need to know which groups they belong. How this can be so complicated, is this made hard intensionnally?

Thanks

trainingcity's picture

Did a quick check and the process outlined by chiebert is working. Thanks for the update!

The view export by chiebert

joshuautley's picture

The view export by chiebert worked for me as well. I just deleted the content pane and added block instead which is what we need for our use case. Saved me some time.

Thank you chiebert!!!

Organic groups

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: