You are here

public function EntityTypeBundleInfo::getAllBundleInfo in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityTypeBundleInfo.php \Drupal\Core\Entity\EntityTypeBundleInfo::getAllBundleInfo()

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 EntityTypeBundleInfoInterface::getAllBundleInfo

1 call to EntityTypeBundleInfo::getAllBundleInfo()
EntityTypeBundleInfo::getBundleInfo in core/lib/Drupal/Core/Entity/EntityTypeBundleInfo.php
Gets the bundle info of an entity type.

File

core/lib/Drupal/Core/Entity/EntityTypeBundleInfo.php, line 87

Class

EntityTypeBundleInfo
Provides discovery and retrieval of entity type bundles.

Namespace

Drupal\Core\Entity

Code

public function getAllBundleInfo() {
  if (empty($this->bundleInfo)) {
    $langcode = $this->languageManager
      ->getCurrentLanguage()
      ->getId();
    if ($cache = $this
      ->cacheGet("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) {

        // First look for entity types that act as bundles for others, load them
        // and add them as bundles.
        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();
          }
        }
        elseif (!isset($this->bundleInfo[$type])) {
          $this->bundleInfo[$type][$type]['label'] = $entity_type
            ->getLabel();
        }
      }
      $this->moduleHandler
        ->alter('entity_bundle_info', $this->bundleInfo);
      $this
        ->cacheSet("entity_bundle_info:{$langcode}", $this->bundleInfo, Cache::PERMANENT, [
        'entity_types',
        'entity_bundles',
      ]);
    }
  }
  return $this->bundleInfo;
}