Skip to content
Snippets Groups Projects

Resolves #3186688

Open Claudiu Cristea requested to merge issue/drupal-3186688:3186688-label into 9.4.x
1 unresolved thread
Files
4
@@ -92,12 +92,14 @@ public function getAllBundleInfo() {
}
else {
$this->bundleInfo = $this->moduleHandler->invokeAll('entity_bundle_info');
$config_entity_bundle_labels = [];
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();
+2
$config_entity_bundle_labels[$type][$entity->id()] = $entity->label();
}
}
// If entity type bundles are not supported and
@@ -108,6 +110,8 @@ public function getAllBundleInfo() {
}
}
$this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo);
// Check for altered labels of bundles stored as config entities.
$this->checkConfigEntityBundleAlteredLabels($config_entity_bundle_labels);
$this->cacheSet("entity_bundle_info:$langcode", $this->bundleInfo, Cache::PERMANENT, ['entity_types', 'entity_bundles']);
}
}
@@ -125,4 +129,37 @@ public function clearCachedBundles() {
$this->typedDataManager->clearCachedDefinitions();
}
/**
* Checks for altered labels of bundles stored as config entities.
*
* @param array $config_entity_bundle_labels
* A list of labels of config entity bundles grouped by entity type.
*/
protected function checkConfigEntityBundleAlteredLabels(array $config_entity_bundle_labels): void {
// Collect the IDs of all bundles stored as config entities whose labels
// were altered via hook_entity_bundle_info_alter().
$altered_label_bundles = [];
foreach ($config_entity_bundle_labels as $entity_type_id => $bundles) {
foreach ($bundles as $bundle => $label) {
$altered_label = $this->bundleInfo[$entity_type_id][$bundle]['label'] ?? NULL;
if ($altered_label !== $label) {
$altered_label_bundles[$entity_type_id][] = $bundle;
}
}
}
if ($altered_label_bundles) {
$altered_label_bundles_string = trim(
array_reduce(
array_keys($altered_label_bundles),
function (string $string, string $entity_type_id) use ($altered_label_bundles): string {
return $string . implode(', ', $altered_label_bundles[$entity_type_id]) . " ({$entity_type_id}) ";
},
''
)
);
// @todo Convert deprecation to exception in drupal:10.0.0.
@trigger_error("Using hook_entity_bundle_info_alter() to alter the label of bundles stored as config entities is deprecated in drupal:9.4.0 and is not permitted in drupal:10.0.0. Label altered bundles: {$altered_label_bundles_string}. Use different methods to alter the label for bundles stored as config entities. See https://www.drupal.org/node/3186694", E_USER_DEPRECATED);
}
}
}
Loading