You are here

public function GroupMenuService::getGroupMenus in Group Menu 8

Get all group menu objects.

We create a static cache of group menus since loading them individually has a big impact on performance.

Return value

\Drupal\system\MenuInterface[][] A nested array containing all group menu objects keyed by group ID.

1 call to GroupMenuService::getGroupMenus()
GroupMenuService::loadUserGroupMenusByGroup in src/GroupMenuService.php
Load a list of menus for a group where a user can perform a operation.

File

src/GroupMenuService.php, line 184

Class

GroupMenuService
Checks access for displaying menu pages.

Namespace

Drupal\groupmenu

Code

public function getGroupMenus() {
  if (!$this->groupMenus) {
    $plugin_id = 'group_menu:menu';
    $menus = $this->entityTypeManager
      ->getStorage('menu')
      ->loadMultiple();
    $group_content_types = $this->entityTypeManager
      ->getStorage('group_content_type')
      ->loadByContentPluginId($plugin_id);
    if (!empty($group_content_types)) {
      $group_contents = $this->entityTypeManager
        ->getStorage('group_content')
        ->loadByProperties([
        'type' => array_keys($group_content_types),
      ]);
      foreach ($group_contents as $group_content) {

        // Make sure the group and entity IDs are set in the group content
        // entity.
        if (!isset($group_content->gid->target_id) || !isset($group_content->entity_id->target_id)) {
          continue;
        }

        /** @var \Drupal\group\Entity\GroupContentInterface $group_content */
        $this->groupMenus[$group_content->gid->target_id][$group_content->entity_id->target_id] = $menus[$group_content->entity_id->target_id];
      }
    }
  }
  return $this->groupMenus;
}