EntityTypeBundleInfo::getAllBundleInfo

public 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

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();
          }
        }
        // If entity type bundles are not supported and
        // hook_entity_bundle_info() has not already set up bundle
        // information, use the entity type name and 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;
}
doc_Drupal
2016-10-29 09:08:10
Comments
Leave a Comment

Please login to continue.