function EntityTypeBundleInfo::getAllBundleInfo
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Entity/EntityTypeBundleInfo.php \Drupal\Core\Entity\EntityTypeBundleInfo::getAllBundleInfo()
- 10 core/lib/Drupal/Core/Entity/EntityTypeBundleInfo.php \Drupal\Core\Entity\EntityTypeBundleInfo::getAllBundleInfo()
- 9 core/lib/Drupal/Core/Entity/EntityTypeBundleInfo.php \Drupal\Core\Entity\EntityTypeBundleInfo::getAllBundleInfo()
- 8.9.x 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 94
Class
- EntityTypeBundleInfo
- Provides discovery and retrieval of entity type bundles.
Namespace
Drupal\Core\EntityCode
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();
}
// Add bundle information provided by entity type plugin discovery
// using the Drupal\Core\Entity\Attribute\Bundle attribute.
$attribute_entity_type_bundle_info = $entity_type->get('entity_type_bundle_info');
if ($attribute_entity_type_bundle_info === NULL) {
continue;
}
foreach ($attribute_entity_type_bundle_info as $bundle => $info) {
if ($bundle_entity_type && !isset($this->bundleInfo[$type][$bundle])) {
// If the entity type has a bundle entity type, do not allow
// bundle definitions to be created by attributes.
continue;
}
$this->bundleInfo[$type][$bundle]['class'] = $info['class'];
$additional_bundle_info = array_filter([
'label' => $info['label'],
'translatable' => $info['translatable'],
], fn($property) => $property !== NULL);
$this->bundleInfo[$type][$bundle] = $additional_bundle_info + $this->bundleInfo[$type][$bundle];
// Make sure the bundle has a label.
$this->bundleInfo[$type][$bundle]['label'] ??= $bundle;
}
}
$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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.