You are here

protected function GroupSelectorWidget::getSelectableGroups in Opigno calendar event 8

Same name and namespace in other branches
  1. 3.x modules/opigno_calendar_event_group/src/GroupSelectorWidget.php \Drupal\opigno_calendar_event_group\GroupSelectorWidget::getSelectableGroups()

Returns the groups the entity belongs to.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: An entity object.

Return value

\Drupal\group\Entity\GroupInterface[] An array of group entities.

1 call to GroupSelectorWidget::getSelectableGroups()
GroupSelectorWidget::alterForm in modules/opigno_calendar_event_group/src/GroupSelectorWidget.php
Alters the parent form.

File

modules/opigno_calendar_event_group/src/GroupSelectorWidget.php, line 165

Class

GroupSelectorWidget
Provides a widget to select calendar event groups.

Namespace

Drupal\opigno_calendar_event_group

Code

protected function getSelectableGroups(ContentEntityInterface $entity) {
  $groups = [];
  try {

    /** @var \Drupal\group\Entity\Storage\GroupContentStorageInterface $storage */
    $storage = $this->entityTypeManager
      ->getStorage('group_content');

    // @todo Scalability improvement: use an aggregate entity query instead.

    /** @var \Drupal\group\Entity\GroupContentInterface $group_content */
    foreach ($storage
      ->loadByEntity($entity) as $group_content) {
      $group = $group_content
        ->getGroup();
      $groups[$group
        ->id()] = $group;
    }
  } catch (InvalidPluginDefinitionException $e) {
    $this
      ->logException($e);
  }
  return $groups;
}