You are here

protected function GroupTypeManager::populateGroupRelationMap in Organic groups 8

Populates the map of relations between group types and group content types.

1 call to GroupTypeManager::populateGroupRelationMap()
GroupTypeManager::getGroupRelationMap in src/GroupTypeManager.php
Returns the group relation map.

File

src/GroupTypeManager.php, line 373

Class

GroupTypeManager
A manager to keep track of which entity type/bundles are OG group enabled.

Namespace

Drupal\og

Code

protected function populateGroupRelationMap() : void {

  // Retrieve a cached version of the map if it exists.
  if ($cached_map = $this
    ->getCachedGroupRelationMap()) {
    $this->groupRelationMap = $cached_map;
    return;
  }
  $this->groupRelationMap = [];
  $user_bundles = $this->entityTypeManager
    ->getDefinition('user')
    ->getKey('bundle') ?: [
    'user',
  ];
  foreach ($this->entityTypeBundleInfo
    ->getAllBundleInfo() as $group_content_entity_type_id => $bundles) {
    foreach ($bundles as $group_content_bundle_id => $bundle_info) {
      if (in_array($group_content_bundle_id, $user_bundles)) {

        // User is not a group content per se. Remove it.
        continue;
      }
      foreach ($this
        ->getGroupBundleIdsByGroupContentBundle($group_content_entity_type_id, $group_content_bundle_id) as $group_entity_type_id => $group_bundle_ids) {
        foreach ($group_bundle_ids as $group_bundle_id) {
          $this->groupRelationMap[$group_entity_type_id][$group_bundle_id][$group_content_entity_type_id][$group_content_bundle_id] = $group_content_bundle_id;
        }
      }
    }
  }

  // Cache the map.
  $this->cache
    ->set(self::GROUP_RELATION_MAP_CACHE_KEY, $this->groupRelationMap);
}