0

I want to output the membership of a drupal group, but limiting the number of members shown, instead of outputting all members at once, (that i can do with the code bellow).

    $members = $group->getContentEntities('group_membership');

1 Answer 1

1

If you are able to build an entity query for the group members you can use $query->pager(). See block to display nodes using entityQuery with pager

If not, you have to calculate the pager variables yourself. There is only one example for a pager in core that is not using a pager query, the taxonomy terms overview OverviewTerms::buildForm. Or you can use pager_default_initialize().

And a third and probably quickest solution is to build a view for the group members.

3
  • I cold do something like this: \Drupal::entityQuery('group_content') ->condition('gid', $group->id()) ->condition('type', "{$bundle}-group_membership") ->range(0, 4) ->execute(); but can i pass without the bundle? I only want the membership. Commented Mar 29, 2017 at 19:12
  • I don't have the module group installed, but can't you just use only the 'gid' condition?. Instead of range() use pager(), so that you can use the built in pager element.
    – 4uk4
    Commented Mar 29, 2017 at 19:20
  • group_content returns both the users and the associated nodes, so i must specify what i want. I was hoping there was some way to avoid it. Commented Mar 29, 2017 at 19:24

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.