You are here

public function MembershipManager::getGroupCount in Organic groups 8

Returns the number of groups associated with a given group content entity.

Do not use this to retrieve the group membership count for a user entity. Use count(\Drupal\og\MembershipManager::getUserGroupIds()) instead.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The group content entity for which to count the associated groups.

string $group_type_id: Only count groups of this entity type.

string $group_bundle: Only count groups of this bundle.

Return value

int The number of associated groups.

Overrides MembershipManagerInterface::getGroupCount

File

src/MembershipManager.php, line 358

Class

MembershipManager
Service for managing memberships and group content.

Namespace

Drupal\og

Code

public function getGroupCount(EntityInterface $entity, $group_type_id = NULL, $group_bundle = NULL) {
  return array_reduce($this
    ->getGroupIds($entity, $group_type_id, $group_bundle), function ($carry, $item) {
    return $carry + count($item);
  }, 0);
}