diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 7e14f56f73..a2f4e9f577 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -19,7 +19,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Url; -use Drupal\entity_test\Entity\EntityTestKeys; +use Drupal\entity_test\Entity\EntityTest; /** * Filter that limits test entity list to revisable ones. @@ -103,8 +103,8 @@ function entity_test_entity_type_alter(array &$entity_types) { unset($entity_types['entity_test_new']); } - $entity_test_keys_definition = $entity_types['entity_test_keys']; - $entity_test_keys_definition->set('entity_keys', $state->get('entity_test_keys.entity_keys', EntityTestKeys::defaultEntityKeys())); + $entity_test_definition = $entity_types['entity_test']; + $entity_test_definition->set('entity_keys', $state->get('entity_test.entity_keys', EntityTest::defaultEntityKeys())); } /** diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php index 9f8c5b0521..77b295f6ae 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php @@ -33,13 +33,7 @@ * admin_permission = "administer entity_test content", * persistent_cache = FALSE, * list_cache_contexts = { "entity_test_view_grants" }, - * entity_keys = { - * "id" = "id", - * "uuid" = "uuid", - * "bundle" = "type", - * "label" = "name", - * "langcode" = "langcode", - * }, + * entity_keys = {}, * links = { * "canonical" = "/entity_test/{entity_test}", * "add-form" = "/entity_test/add", @@ -109,7 +103,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ], ]); - return $fields; + return $fields + \Drupal::state()->get($entity_type->id() . '.additional_base_field_definitions', []);; } /** @@ -164,4 +158,31 @@ public function getName() { return $this->get('name')->value; } + /** + * {@inheritdoc} + */ + public function getEntityKey($key) { + return parent::getEntityKey($key); + } + + /** + * Default entity keys used for a working entity type. + * + * @return array + * An array of entity keys. + * + * @see entity_test_entity_type_alter + */ + public static function defaultEntityKeys() { + return [ + 'id' => 'id', + 'uuid' => 'uuid', + 'bundle' => 'type', + 'label' => 'name', + 'langcode' => 'langcode', + 'default_langcode' => 'default_langcode', + 'revision_translation_affected' => 'revision_translation_affected', + ]; + } + } diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestKeys.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestKeys.php deleted file mode 100644 index 290bd896b0..0000000000 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestKeys.php +++ /dev/null @@ -1,76 +0,0 @@ -get($entity_type->id() . '.additional_base_field_definitions', []); - } - - /** - * {@inheritdoc} - */ - public function getEntityKey($key) { - return parent::getEntityKey($key); - } - - /** - * Default entity keys used for a working entity type. - * - * @return array - * An array of entity keys. - * - * @see entity_test_entity_type_alter - */ - public static function defaultEntityKeys() { - return [ - 'id' => 'id', - 'uuid' => 'uuid', - 'revision' => 'revision_id', - 'label' => 'name', - 'langcode' => 'langcode', - 'default_langcode' => 'default_langcode', - 'revision_translation_affected' => 'revision_translation_affected', - ]; - } - -} diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityKeysTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityKeysTest.php index 03dc8b5c31..f799da7c35 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityKeysTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityKeysTest.php @@ -3,7 +3,7 @@ namespace Drupal\KernelTests\Core\Entity; use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\entity_test\Entity\EntityTestKeys; +use Drupal\entity_test\Entity\EntityTest; /** * Test the behavior of entity keys. @@ -18,7 +18,7 @@ class EntityKeysTest extends EntityKernelTestBase { * @dataProvider multipleKeysCacheTestCases */ public function testMultipleKeysCache($translatable) { - $this->state->set('entity_test_keys.additional_base_field_definitions', [ + $this->state->set('entity_test.additional_base_field_definitions', [ 'test_field' => BaseFieldDefinition::create('string')->setTranslatable($translatable), ]); $this->setupTestEntityKeys([ @@ -26,9 +26,9 @@ public function testMultipleKeysCache($translatable) { 'key_2' => 'test_field', ]); drupal_flush_all_caches(); - $this->installEntitySchema('entity_test_keys'); + $this->installEntitySchema('entity_test'); - $entity = EntityTestKeys::create([]); + $entity = EntityTest::create([]); $entity->set('test_field', 'foo'); $this->assertEquals('foo', $entity->getEntityKey('key_1')); @@ -60,7 +60,7 @@ public function multipleKeysCacheTestCases() { * Keys to set. */ protected function setupTestEntityKeys($keys) { - $this->state->set('entity_test_keys.entity_keys', EntityTestKeys::defaultEntityKeys() + $keys); + $this->state->set('entity_test.entity_keys', EntityTest::defaultEntityKeys() + $keys); } }