4

I am migrating a site from using OG 7.x-1.4 to OG 7.x-2.3. The migration seemed to go fine, but it broke the view that shows the current users group (i.e. groups the user is a member of). In the original view for 1.4, it had a contextual filter:

  • (OG membership from OG group) We pass to the "Entity ID" the User ID.

And the following relationships:

  • OG group: OG group from Node
  • (node being the OG group) OG group: OG membership from OG group

However, the new Organic Groups 7.x-2.3 now uses the OGMembership data model and I cannot figure out how to recreate this view using OGMembership, as I am not clear exactly how it works and I cannot seem to find any in-depth documentation for this kind of thing.

11

This is how to get the OG membership ID:s to start with.

Add new view. Show -> OG membership (important!) Then in some display add a contextual filter -> OG membership: Entity id. Provide default value -> Type -> User ID from logged in user. Override title: %1's groups. Specify validation criteria -> User.

Now you have the list of ID:s.

Next to get the actual titles of the groups (as the base table is OG membership, not node), Add a relationship -> Group Node from OG membership. Add a field -> Content: Title. Relationship -> Group node from OG membership.

Now you have the titles too. Add some filters and sort criterias to taste.

  • Thanks so much for the great answer. That worked like a charm! I did not realize you could create a view of OG memberships. That was an eye opener. If it's permissible to ask a follow up question, can you tell me how I'd show the number of members in each group? – VirtualMitra Sep 5 '13 at 0:15
  • No, sorry. Here is the discussion everybody is linking to: drupal.org/node/1101102 – Kari Kääriäinen Sep 5 '13 at 7:45
  • Don't forget to accept the answer. It helps you, me, and the community. meta.stackexchange.com/questions/5234/… – Kari Kääriäinen Sep 6 '13 at 5:58
  • Thanks for pointing that out. I didn't understand. I tried to upvote but didn't have a high enough reputation, and I didn't see the checkmark icon. – VirtualMitra Sep 6 '13 at 12:41
0

Here is the export for a view that does the job as described by Kari Kääriäinen above.

$view = new view();
$view->name = 'my_groups';
$view->description = 'List of Groups I\'m Subscribed To';
$view->tag = 'default';
$view->base_table = 'og_membership';
$view->human_name = 'My 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['title'] = 'My Groups';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'role';
$handler->display->display_options['access']['role'] = array(
  2 => '2',
);
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '200';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'table';
/* Field: OG membership: Delete link */
$handler->display->display_options['fields']['delete_membership']['id'] = 'delete_membership';
$handler->display->display_options['fields']['delete_membership']['table'] = 'og_membership';
$handler->display->display_options['fields']['delete_membership']['field'] = 'delete_membership';
$handler->display->display_options['fields']['delete_membership']['label'] = 'Remove';
/* Field: OG membership: Edit link */
$handler->display->display_options['fields']['edit_membership']['id'] = 'edit_membership';
$handler->display->display_options['fields']['edit_membership']['table'] = 'og_membership';
$handler->display->display_options['fields']['edit_membership']['field'] = 'edit_membership';
$handler->display->display_options['fields']['edit_membership']['label'] = 'Edit';
/* Field: OG membership: Rendered OG membership */
$handler->display->display_options['fields']['rendered_entity']['id'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['table'] = 'views_entity_og_membership';
$handler->display->display_options['fields']['rendered_entity']['field'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['link_to_entity'] = 1;
$handler->display->display_options['fields']['rendered_entity']['bypass_access'] = 0;
/* Contextual filter: OG membership: 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']['default_action'] = 'default';
$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';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'my_groups';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'My Groups';
$handler->display->display_options['menu']['description'] = 'Groups that I am subscribed to';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;
$translatables['my_groups'] = array(
  t('Master'),
  t('My Groups'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('« first'),
  t('‹ previous'),
  t('next ›'),
  t('last »'),
  t('Remove'),
  t('Edit'),
  t('Rendered OG membership'),
  t('All'),
  t('Page'),
);

$view = new view();
$view->name = 'my_groups';
$view->description = 'List of Groups I\'m Subscribed To';
$view->tag = 'default';
$view->base_table = 'og_membership';
$view->human_name = 'My 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['title'] = 'My Groups';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'role';
$handler->display->display_options['access']['role'] = array(
  2 => '2',
);
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '200';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'table';
/* Field: OG membership: Delete link */
$handler->display->display_options['fields']['delete_membership']['id'] = 'delete_membership';
$handler->display->display_options['fields']['delete_membership']['table'] = 'og_membership';
$handler->display->display_options['fields']['delete_membership']['field'] = 'delete_membership';
$handler->display->display_options['fields']['delete_membership']['label'] = 'Remove';
/* Field: OG membership: Edit link */
$handler->display->display_options['fields']['edit_membership']['id'] = 'edit_membership';
$handler->display->display_options['fields']['edit_membership']['table'] = 'og_membership';
$handler->display->display_options['fields']['edit_membership']['field'] = 'edit_membership';
$handler->display->display_options['fields']['edit_membership']['label'] = 'Edit';
/* Field: OG membership: Rendered OG membership */
$handler->display->display_options['fields']['rendered_entity']['id'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['table'] = 'views_entity_og_membership';
$handler->display->display_options['fields']['rendered_entity']['field'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['link_to_entity'] = 1;
$handler->display->display_options['fields']['rendered_entity']['bypass_access'] = 0;
/* Contextual filter: OG membership: 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']['default_action'] = 'default';
$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';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'my_groups';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'My Groups';
$handler->display->display_options['menu']['description'] = 'Groups that I am subscribed to';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;
$translatables['my_groups'] = array(
  t('Master'),
  t('My Groups'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('« first'),
  t('‹ previous'),
  t('next ›'),
  t('last »'),
  t('Remove'),
  t('Edit'),
  t('Rendered OG membership'),
  t('All'),
  t('Page'),
);

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.