You are here

public function EntityTypeBundleInfo::getAllBundleInfo in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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 all bundle information.

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 92
Contains \Drupal\Core\Entity\EntityTypeBundleInfo.

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;
}