Commit 20762532 authored by alexpott's avatar alexpott

Issue #3052140 by amateescu, dpi, xjm: Cannot convert custom entity types from...

Issue #3052140 by amateescu, dpi, xjm: Cannot convert custom entity types from non-revisionable to revisionable with pre-8.7.x compatible methods
parent fe4efbd8
......@@ -96,7 +96,7 @@ public function convertToRevisionable(array &$sandbox, array $fields_to_update =
/** @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $last_installed_schema_repository */
$last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
$field_storage_definitions = $last_installed_schema_repository->getLastInstalledFieldStorageDefinitions('entity_test_update');
$field_storage_definitions = $last_installed_schema_repository->getLastInstalledFieldStorageDefinitions($this->entityTypeId);
// Add the revision ID field.
$field_name = $entity_type->getKey('revision');
......
......@@ -101,6 +101,10 @@ function entity_test_entity_type_alter(array &$entity_types) {
if (!$state->get('entity_test_new')) {
unset($entity_types['entity_test_new']);
}
else {
// Allow tests to override the entity type definition.
$entity_types['entity_test_new'] = \Drupal::state()->get('entity_test_new.entity_type', $entity_types['entity_test_new']);
}
$entity_test_definition = $entity_types['entity_test'];
$entity_test_definition->set('entity_keys', $state->get('entity_test.entity_keys', []) + $entity_test_definition->getKeys());
......
<?php
namespace Drupal\KernelTests\Core\Entity;
use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter;
use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
/**
* Tests the SqlContentEntityStorageSchemaConverter class.
*
* @coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter
*
* @group Entity
* @group legacy
*/
class SqlContentEntityStorageSchemaConverterTest extends EntityKernelTestBase {
use EntityDefinitionTestTrait;
/**
* @covers ::convertToRevisionable
*
* @expectedDeprecation \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter is deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::updateFieldableEntityType() instead. See https://www.drupal.org/node/3029997.
*/
public function testConvertToRevisionable() {
$schema = \Drupal::database()->schema();
$this->assertFalse($schema->tableExists('entity_test_new'), 'Schema for the "entity_test_new" entity type does not exist.');
// Check that the "entity_test_new" schema has been created.
$this->enableNewEntityType();
$this->assertTrue($schema->tableExists('entity_test_new'), 'Schema for the "entity_test_new" entity type has been created.');
// Update the entity type definition to revisionable.
$entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_new');
$keys = $entity_type->getKeys();
$keys['revision'] = 'revision_id';
$entity_type->set('entity_keys', $keys);
$entity_type->set('revision_table', 'entity_test_new_revision');
$this->state->set('entity_test_new.entity_type', $entity_type);
\Drupal::entityTypeManager()->clearCachedDefinitions();
$revisionable_schema_converter = new SqlContentEntityStorageSchemaConverter(
'entity_test_new',
\Drupal::entityTypeManager(),
\Drupal::entityDefinitionUpdateManager()
);
$sandbox = [];
$revisionable_schema_converter->convertToRevisionable($sandbox, []);
$this->assertTrue($schema->tableExists('entity_test_new_revision'), 'Schema for the "entity_test_new" entity type has been created.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment