You are here

public function AttachMediaToGroup::getContentGroups in Group Media 8.2

Gets the groups by entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: Entity to check.

Return value

\Drupal\group\Entity\GroupInterface[] Groups that the current entity belongs too.

1 call to AttachMediaToGroup::getContentGroups()
AttachMediaToGroup::attach in src/AttachMediaToGroup.php
Attach media items from given entity to the same group(s).

File

src/AttachMediaToGroup.php, line 231

Class

AttachMediaToGroup
Class AttachMediaToGroup.

Namespace

Drupal\groupmedia

Code

public function getContentGroups(EntityInterface $entity) {
  $groups = [];
  if ($entity instanceof GroupContentInterface) {
    $groups[] = $entity
      ->getGroup();
  }
  elseif ($entity instanceof ContentEntityInterface) {
    $group_contents = $this->groupContentStorage
      ->loadByEntity($entity);
    foreach ($group_contents as $group_content) {
      $groups[] = $group_content
        ->getGroup();
    }
  }

  // Allow other modules to alter.
  $this->moduleHandler
    ->alter('groupmedia_entity_group', $groups, $entity);
  return $groups;
}