I'm trying to create lists of groups using Views. It's simple enough to make a list with gid:s but I'm struggling to display their actual names (titles).

I'm using the relationship User: Group membership to get the groups a user is a member of and the field Group membership: Group gid (Group gid) but can't figure out how to get the name from the gid.

Comments

Psyphil created an issue. See original summary.

ctrlADel’s picture

You are close, you just need to add one more relationship. Group membership -> Group membership: Group gid. That loads the group from the group membership and makes fields on the group available.

Since you are trying to display groups though I would create a view like this. This one is displaying groups and uses a relationship to group memberships and a uid as a contextual filter to display only groups the uid is a member of.

$view = new view();
$view->name = 'test_group_memberships';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'groups';
$view->human_name = 'Test group memberships';
$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'] = 'none';
$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'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Group: Group membership */
$handler->display->display_options['relationships']['group_membership']['id'] = 'group_membership';
$handler->display->display_options['relationships']['group_membership']['table'] = 'groups';
$handler->display->display_options['relationships']['group_membership']['field'] = 'group_membership';
/* Field: Group: Group ID */
$handler->display->display_options['fields']['gid']['id'] = 'gid';
$handler->display->display_options['fields']['gid']['table'] = 'groups';
$handler->display->display_options['fields']['gid']['field'] = 'gid';
/* Field: Group: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'groups';
$handler->display->display_options['fields']['title']['field'] = 'title';
/* Contextual filter: Group membership: User uid */
$handler->display->display_options['arguments']['user']['id'] = 'user';
$handler->display->display_options['arguments']['user']['table'] = 'group_membership';
$handler->display->display_options['arguments']['user']['field'] = 'user';
$handler->display->display_options['arguments']['user']['relationship'] = 'group_membership';
$handler->display->display_options['arguments']['user']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['user']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['user']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['user']['summary_options']['items_per_page'] = '25';

kristiaanvandeneynde’s picture

As ctrlADel has said above: If you want a view of groups, I suggest you create such a view and then you can easily add the groups' fields to the view. If you want a view which lists more than just groups, I suggest you try to decide which "base table" makes most sense and go from there.

For instance: If you want a list of nodes with a field saying what group they're in, start with a node view and add a "Node: Parent group" relationship to the group they belong to. If you want a list of groups with one field listing the amount of nodes in the group, start with a group view and add a relationship to "Group: node content" and work with that.

I'm using the relationship User: Group membership to get the groups a user is a member of and the field Group membership: Group gid (Group gid) but can't figure out how to get the name from the gid.

In this case, you need to create a Group view and add a relationship to the group members. Then you can add a contextual filter on the membership's uid property. Or, in case you also want to show the user's fields in the view, you could even add a 2nd relationship from the membership to the user and contextually filter on the user's uid.

Rustan’s picture

Status: Active » Fixed

Seems solved. Added to howtos.

kristiaanvandeneynde’s picture

Adding fix credit.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.