diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index de73e57..7eb994c 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -444,18 +444,13 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $ try { $has_data = $this->storage->countFieldData($storage_definition, TRUE); - // @todo Add support for deleting bundle fields. + // @todo Add support for deleting bundle fields. Bundle field definitions + // are also using the \Drupal\Core\Field\BaseFieldDefinition class, but + // their isBaseField() method returns FALSE. // @see https://www.drupal.org/node/2907780 if ($storage_definition instanceof BaseFieldDefinition && !$storage_definition->isBaseField() && $has_data) { throw new FieldStorageDefinitionUpdateForbiddenException('Unable to delete a field (' . $storage_definition->getName() . ' in ' . $storage_definition->getTargetEntityTypeId() . ' entity) with data that cannot be purged.'); } - - // If the field storage does not have any data, we can safely delete its - // schema. - if (!$has_data) { - $this->performFieldSchemaOperation('delete', $storage_definition); - return; - } } catch (DatabaseExceptionWrapper $e) { // This may happen when changing field storage schema, since we are not @@ -465,7 +460,14 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $ return; } - // There's nothing to do if the field storage uses a custom storage. + // If the field storage does not have any data, we can safely delete its + // schema. + if (!$has_data) { + $this->performFieldSchemaOperation('delete', $storage_definition); + return; + } + + // There's nothing else we can do if the field storage has a custom storage. if ($storage_definition->hasCustomStorage()) { return; } @@ -520,14 +522,15 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $ } try { // Copy the data from the base table. - $base_table = $this->entityType->isTranslatable() ? $this->storage->getDataTable() : $this->storage->getBaseTable(); + $is_translatable = $this->entityType->isTranslatable() && $storage_definition->isTranslatable(); + $base_table = $is_translatable ? $this->storage->getDataTable() : $this->storage->getBaseTable(); $this->database->insert($dedicated_table_name) ->from($this->getSelectQueryForFieldStorageDeletion($base_table, $shared_table_field_columns, $dedicated_table_field_columns)) ->execute(); // Copy the data from the revision table. if ($this->entityType->isRevisionable()) { - $revision_table = $this->entityType->isTranslatable() ? $this->storage->getRevisionDataTable() : $this->storage->getRevisionTable(); + $revision_table = $is_translatable ? $this->storage->getRevisionDataTable() : $this->storage->getRevisionTable(); $this->database->insert($dedicated_revision_table_name) ->from($this->getSelectQueryForFieldStorageDeletion($revision_table, $shared_table_field_columns, $dedicated_table_field_columns, $base_table)) ->execute(); @@ -614,7 +617,8 @@ protected function getSelectQueryForFieldStorageDeletion($table_name, array $sha $select->addExpression(':langcode', 'langcode', [':langcode' => LanguageInterface::LANGCODE_DEFAULT]); } - // Add the delta column. + // Add the delta column and set it to 0 because we are only dealing with + // single cardinality fields. $select->addExpression(':delta', 'delta', [':delta' => 0]); // Add all the dynamic field columns. diff --git a/core/lib/Drupal/Core/Field/BaseFieldDefinition.php b/core/lib/Drupal/Core/Field/BaseFieldDefinition.php index 5a53eb7..4dbf61e 100644 --- a/core/lib/Drupal/Core/Field/BaseFieldDefinition.php +++ b/core/lib/Drupal/Core/Field/BaseFieldDefinition.php @@ -818,7 +818,7 @@ public function getUniqueIdentifier() { * {@inheritdoc} */ public function isDeleted() { - return isset($this->definition['deleted']) ? (bool) $this->definition['deleted'] : FALSE; + return !empty($this->definition['deleted']); } /**