You are here

function datalayer_get_entity_group in dataLayer 8

Get the group of given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

Return value

null|\Drupal\group\Entity\GroupInterface Return the Group if found, else NULL.

1 call to datalayer_get_entity_group()
_datalayer_get_entity_data in ./datalayer.module
Collect entity data for output and altering.

File

./datalayer.module, line 581
Client-side data space.

Code

function datalayer_get_entity_group(EntityInterface $entity) {

  // Load all the group content for this node.
  $group_content_types = GroupContentType::loadByContentPluginId("group_node:{$entity->bundle()}");
  $group_contents = \Drupal::entityTypeManager()
    ->getStorage('group_content')
    ->loadByProperties([
    'type' => array_keys($group_content_types),
    'entity_id' => $entity
      ->id(),
  ]);

  // Get this nodes group.
  if (!empty($group_contents)) {

    /** @var \Drupal\group\Entity\GroupContent $group_cotnent */
    $group_content = reset($group_contents);

    /** @var \Drupal\group\Entity\Group $group */
    return $group_content
      ->getGroup();
  }
  return NULL;
}