X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffield%2Fsrc%2FEntity%2FFieldConfig.php;h=49b9141450bf1ad88113c4a5f3a6442b86598428;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=af2fcca738e7fe5c950a277985536fbf004fd438;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/field/src/Entity/FieldConfig.php b/web/core/modules/field/src/Entity/FieldConfig.php index af2fcca73..49b914145 100644 --- a/web/core/modules/field/src/Entity/FieldConfig.php +++ b/web/core/modules/field/src/Entity/FieldConfig.php @@ -3,6 +3,7 @@ namespace Drupal\field\Entity; use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\FieldableEntityStorageInterface; use Drupal\Core\Field\FieldConfigBase; use Drupal\Core\Field\FieldException; use Drupal\field\FieldStorageConfigInterface; @@ -189,13 +190,19 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface { */ public static function preDelete(EntityStorageInterface $storage, array $fields) { $state = \Drupal::state(); + $entity_type_manager = \Drupal::entityTypeManager(); parent::preDelete($storage, $fields); // Keep the field definitions in the state storage so we can use them // later during field_purge_batch(). $deleted_fields = $state->get('field.field.deleted') ?: []; + + /** @var \Drupal\field\FieldConfigInterface $field */ foreach ($fields as $field) { - if (!$field->deleted) { + // Only mark a field for purging if there is data. Otherwise, just remove + // it. + $target_entity_storage = $entity_type_manager->getStorage($field->getTargetEntityTypeId()); + if (!$field->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field->getFieldStorageDefinition(), TRUE)) { $config = $field->toArray(); $config['deleted'] = TRUE; $config['field_storage_uuid'] = $field->getFieldStorageDefinition()->uuid();