diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index 9f77bf3..d448e51 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -1017,10 +1017,8 @@ public function onFieldDelete(FieldStorageDefinitionInterface $storage_definitio // Move the table to a unique name while the table contents are being // deleted. - $deleted_field = clone $storage_definition; - $deleted_field->deleted = TRUE; - $new_table = static::_fieldTableName($deleted_field); - $revision_new_table = static::_fieldRevisionTableName($deleted_field); + $new_table = static::_fieldTableName($storage_definition, TRUE); + $revision_new_table = static::_fieldRevisionTableName($storage_definition, TRUE); $this->database->schema()->renameTable($table, $new_table); $this->database->schema()->renameTable($revision_table, $revision_new_table); } @@ -1112,6 +1110,9 @@ public function onFieldPurge(FieldStorageDefinitionInterface $storage_definition * The field storage definition. * @param array $schema * The field schema array. Mandatory for upgrades, omit otherwise. + * @param bool $deleted + * (optional) Whether the schema of the table holding the values of a + * deleted field should be returned. * * @return array * The same as a hook_schema() implementation for the data and the @@ -1119,8 +1120,11 @@ public function onFieldPurge(FieldStorageDefinitionInterface $storage_definition * * @see hook_schema() */ - public static function _fieldSqlSchema(FieldStorageDefinitionInterface $storage_definition, array $schema = NULL) { - if ($storage_definition->deleted) { + public static function _fieldSqlSchema(FieldStorageDefinitionInterface $storage_definition, array $schema = NULL, $deleted = FALSE) { + if ($storage_definition->deleted && !$deleted) { + throw new \Exception("Field schema for deleted field to be returned."); + } + if ($deleted) { $description_current = "Data storage for deleted field {$storage_definition->getUniqueStorageIdentifier()} ({$storage_definition->getTargetEntityTypeId()}, {$storage_definition->getName()})."; $description_revision = "Revision archive storage for deleted field {$storage_definition->getUniqueStorageIdentifier()} ({$storage_definition->getTargetEntityTypeId()}, {$storage_definition->getName()})."; } @@ -1279,17 +1283,15 @@ public static function _fieldSqlSchema(FieldStorageDefinitionInterface $storage_ * * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition * The field storage definition. + * @param bool $deleted + * (optional) Whether the table name holding the values of a deleted field + * should be returned. * * @return string * A string containing the generated name for the database table. */ - static public function _fieldTableName(FieldStorageDefinitionInterface $storage_definition) { - // Be sure to get the field config object so we check the right deleted - // property. @todo: Fix properly. - if ($storage_definition instanceof FieldInstanceConfigInterface) { - $storage_definition = $storage_definition->getField(); - } - if ($storage_definition->deleted) { + static public function _fieldTableName(FieldStorageDefinitionInterface $storage_definition, $deleted = FALSE) { + if ($deleted) { // When a field is a deleted, the table is renamed to // {field_deleted_data_FIELD_UUID}. To make sure we don't end up with // table names longer than 64 characters, we hash the unique storage @@ -1314,17 +1316,15 @@ static public function _fieldTableName(FieldStorageDefinitionInterface $storage_ * * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition * The field storage definition. + * @param bool $deleted + * (optional) Whether the table name holding the values of a deleted field + * should be returned. * * @return string * A string containing the generated name for the database table. */ - static public function _fieldRevisionTableName(FieldStorageDefinitionInterface $storage_definition) { - // Be sure to get the field config object so we check the right deleted - // property. @todo: Fix properly. - if ($storage_definition instanceof FieldInstanceConfigInterface) { - $storage_definition = $storage_definition->getField(); - } - if ($storage_definition->deleted) { + static public function _fieldRevisionTableName(FieldStorageDefinitionInterface $storage_definition, $deleted = FALSE) { + if ($deleted) { // When a field is a deleted, the table is renamed to // {field_deleted_revision_FIELD_UUID}. To make sure we don't end up with // table names longer than 64 characters, we hash the unique storage