Skip to content
Snippets Groups Projects

Issue #3129179: Provide some way to rebuild the persistent bundle field map

Open Issue #3129179: Provide some way to rebuild the persistent bundle field map
2 unresolved threads
Open Scott Euser requested to merge issue/drupal-3129179:9.3.x into 9.5.x
2 unresolved threads
Files
4
@@ -535,6 +535,7 @@ public function getFieldMap() {
// scale, as the time to query would grow exponentially with more fields
// and bundles. A cache would be deleted during cache clears, which is
// the only time it is needed, so a key value collection is used.
// See ::rebuildBundleFieldMap() for triggering a rebuild.
$bundle_field_maps = $this->keyValueFactory->get('entity.definitions.bundle_field_map')->getAll();
foreach ($bundle_field_maps as $entity_type_id => $bundle_field_map) {
foreach ($bundle_field_map as $field_name => $map_entry) {
@@ -572,6 +573,30 @@ public function getFieldMapByFieldType($field_type) {
return $this->fieldMapByFieldType[$field_type];
}
/**
* {@inheritdoc}
*/
public function rebuildBundleFieldMap() {
$map = [];
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
continue;
}
foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
foreach ($this->getFieldDefinitions($entity_type_id, $bundle) as $field_name => $field_definition) {
if (!$field_definition->getFieldStorageDefinition()->isBaseField()) {
$map[$entity_type_id][$field_name]['type'] = $field_definition->getType();
$map[$entity_type_id][$field_name]['bundles'][$bundle] = $bundle;
}
}
}
}
$persistent_map = $this->keyValueFactory->get('entity.definitions.bundle_field_map');
$persistent_map->deleteAll();
$persistent_map->setMultiple($map);
}
/**
* Builds field storage definitions for an entity type.
*
Loading