Problem/Motivation
Config fields are split between two classes:
- FieldConfigBase, in the Field core component
- FieldConfig, which inherits from it, in the field module.
FieldConfigBase handles clearing caches on save, in postSave():
// Clear the cache.
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
However, for deleting a field, it's in FieldConfig::postDelete():
// Clear the cache upfront, to refresh the results of getBundles().
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Notify the entity storage.
foreach ($fields as $field) {
if (!$field->deleted) {
\Drupal::service('field_definition.listener')->onFieldDefinitionDelete($field);
}
}
This part of the code in postDelete() should be moved up to the parent class for consistency.