+ // Keep the field definition in the deleted fields repository so we can use
+ // it later during field_purge_batch(), but only if the field has data.
+ try {
+ if ($storage_definition instanceof BaseFieldDefinition && $storage instanceof FieldableEntityStorageInterface && $storage->countFieldData($storage_definition, TRUE)) {
+ $deleted_storage_definition = clone $storage_definition;
+ $deleted_storage_definition->setDeleted(TRUE);
+ $this->deletedFieldsRepository->addFieldDefinition($deleted_storage_definition);
+ $this->deletedFieldsRepository->addFieldStorageDefinition($deleted_storage_definition);
+ }
+ }
+ catch (DatabaseExceptionWrapper $e) {
+ // This may happen when changing field storage schema, since we are not
+ // able to use a table mapping matching the passed storage definition.
+ // @todo Revisit this once we are able to instantiate the table mapping
+ // properly. See https://www.drupal.org/node/2274017.
+ }
+