You are here

public function EckEntityTypeBundleInfo::getAllBundleInfo in Entity Construction Kit (ECK) 8

Get the bundle info of all entity types.

Return value

array An array of bundle information where the outer array is keyed by entity type. The next level is keyed by the bundle name. The inner arrays are associative arrays of bundle information, such as the label for the bundle.

Overrides EntityTypeBundleInfo::getAllBundleInfo

File

src/EckEntityTypeBundleInfo.php, line 16

Class

EckEntityTypeBundleInfo
Holds bundle info for eck entity types.

Namespace

Drupal\eck

Code

public function getAllBundleInfo() {
  if (empty($this->bundleInfo)) {
    $langCode = $this->languageManager
      ->getCurrentLanguage()
      ->getId();
    if ($cache = $this
      ->cacheGet("eck_entity_bundle_info:{$langCode}")) {
      $this->bundleInfo = $cache->data;
    }
    else {
      $this->bundleInfo = $this->moduleHandler
        ->invokeAll('entity_bundle_info');
      foreach ($this->entityTypeManager
        ->getDefinitions() as $type => $entity_type) {
        if ($bundle_entity_type = $entity_type
          ->getBundleEntityType()) {
          foreach ($this->entityTypeManager
            ->getStorage($bundle_entity_type)
            ->loadMultiple() as $entity) {
            $this->bundleInfo[$type][$entity
              ->id()]['label'] = $entity
              ->label();
          }
        }
      }
      $this->moduleHandler
        ->alter('entity_bundle_info', $this->bundleInfo);
      $this
        ->cacheSet("eck_entity_bundle_info:{$langCode}", $this->bundleInfo, Cache::PERMANENT, [
        'entity_types',
        'entity_bundles',
      ]);
    }
  }
  return $this->bundleInfo;
}