1

Using the Group module, you can create a group, say 'group ABC', and create or update some nodes so that they belong to that group. But when you visit the "Group ABC" page, you don't see those nodes. Moreover, by browsing the nodes you don't see anything indicating those nodes belong to "Group ABC".

How to list the nodes that belong to a group on the Group page?

Note: This module is available for both Drupal 7 and Drupal 8, and this question applies to both releases.

2 Answers 2

0

To show the content of a group, you need to create a view. The Group module provides Views 'relationships' to any node's parent group.

With that, these are the steps required:

  • Create a view about content.
  • Add a relationship to the parent group.
  • Add a contextual filter on the group's id (gid).
  • Create a page, a block, a content pane, etc (whatever fits your needs).

Below is an export of a (simplified) view created (in Drupal 7) using the steps described above:

$view = new view();
$view->name = 'group_content';
$view->description = 'Show all nodes that belong to a specific group';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Group content';
$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'] = 'Group content';
$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['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
);
$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' => '',
    'empty_column' => 0,
  ),
);
/* Relationship: Content: Parent group */
$handler->display->display_options['relationships']['parent_group']['id'] = 'parent_group';
$handler->display->display_options['relationships']['parent_group']['table'] = 'node';
$handler->display->display_options['relationships']['parent_group']['field'] = 'parent_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']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* 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']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Group: Group ID */
$handler->display->display_options['filters']['gid']['id'] = 'gid';
$handler->display->display_options['filters']['gid']['table'] = 'groups';
$handler->display->display_options['filters']['gid']['field'] = 'gid';
$handler->display->display_options['filters']['gid']['relationship'] = 'parent_group';
$handler->display->display_options['filters']['gid']['exposed'] = TRUE;
$handler->display->display_options['filters']['gid']['expose']['operator_id'] = 'gid_op';
$handler->display->display_options['filters']['gid']['expose']['label'] = 'Group ID';
$handler->display->display_options['filters']['gid']['expose']['operator'] = 'gid_op';
$handler->display->display_options['filters']['gid']['expose']['identifier'] = 'gid';
$handler->display->display_options['filters']['gid']['expose']['required'] = TRUE;
$handler->display->display_options['filters']['gid']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'group-content';
0

Maybe Kristiaan Van den Eynde's reply to the question posted in this node here https://www.drupal.org/node/2689663 will be "enlightening" enough...

or this step-by-step guide here, edited by Pierre Vriens, too: https://www.drupal.org/node/2693847

Or/and this blog post: https://www.optasy.com/blog/drupal-8-group-module-how-list-related-group-content.

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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