diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 3404957..318b84b 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -116,6 +116,8 @@ public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInter $this->configFactory = $config_factory; $this->uuidService = $uuid_service; $this->languageManager = $language_manager; + // The UUID key must be 'uuid'. + $this->uuidKey = 'uuid'; } /** diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php index ab94c27..6fc8df1 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php @@ -29,6 +29,16 @@ class ConfigEntityType extends EntityType implements ConfigEntityTypeInterface { protected $static_cache = FALSE; /** + * An array of entity keys. + * + * Note that the 'langcode' and 'uuid' keys are hardcoded to be 'langcode' and + * 'uuid' and cannot be overridden in the annotation. + * + * @var array + */ + protected $entity_keys = array(); + + /** * Keys that are stored key value store for fast lookup. * * @var array diff --git a/core/modules/config/tests/config_test/src/Entity/ConfigTest.php b/core/modules/config/tests/config_test/src/Entity/ConfigTest.php index 8ad8262..53cca07 100644 --- a/core/modules/config/tests/config_test/src/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/src/Entity/ConfigTest.php @@ -31,7 +31,8 @@ * entity_keys = { * "id" = "id", * "label" = "label", - * "status" = "status" + * "status" = "status", + * "uuid" = "fake_key_to_ensure_this_does_not_work" * }, * links = { * "edit-form" = "/admin/structure/config_test/manage/{config_test}", diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 508f39b..c2e8469 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -9,7 +9,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Entity\ConfigEntityInterface; -use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Config\Entity\ConfigEntityStorage; use Drupal\Core\Language\Language; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -930,6 +930,14 @@ public function testDeleteNothing() { } /** + * @covers ::__construct + */ + public function testUuidKey() { + $storage = new TestConfigEntityStorage($this->entityType, $this->configFactory, $this->uuidService, $this->languageManager); + $this->assertEquals('uuid', $storage->getUuidKey()); + } + + /** * Creates an entity with specific methods mocked. * * @param array $values @@ -945,6 +953,17 @@ public function getMockEntity(array $values = array(), $methods = array()) { } +class TestConfigEntityStorage extends ConfigEntityStorage { + /** + * Override the default set in ConfigEntityStorage. + */ + protected $uuidKey = 'whatevs'; + + public function getUuidKey() { + return $this->uuidKey; + } +} + } namespace { if (!defined('SAVED_NEW')) { diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php index 97bf172..a79f82a 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php @@ -184,4 +184,23 @@ public function providerGetPropertiesToExport() { return $data; } + /** + * Ensures that configuration entity types cannot override the special keys. + * + * @covers ::__construct + */ + public function testSpecialEntityKeys() { + $definition = [ + 'entity_keys' => [ + 'uuid' => 'whatevs', + 'langcode' => 'whatevs', + 'blah' => 'whatevs', + ], + ]; + $config_entity_type = $this->setUpConfigEntityType($definition); + $this->assertEquals('uuid', $config_entity_type->getKey('uuid')); + $this->assertEquals('langcode', $config_entity_type->getKey('langcode')); + $this->assertEquals('whatevs', $config_entity_type->getKey('blah')); + } + }