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
3 unresolved threads
Open paul121 requested to merge issue/drupal-3129179:3129179-rebuild-bundle-field-map into 11.x
3 unresolved threads
Files
4
@@ -534,6 +534,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) {
@@ -571,6 +572,35 @@ 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);
// Delete entity_field_map cache to rebuild with new bundle field map.
if ($this->useCaches && $this->cacheBackend) {
$this->cacheBackend->delete('entity_field_map');
}
}
/**
* Builds field storage definitions for an entity type.
*
Loading