diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php index a0ecdcf..bdeed8c 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php @@ -21,7 +21,7 @@ class ConfigEntityListBuilder extends EntityListBuilder { * {@inheritdoc} */ public function load() { - $entities = parent::load(); + $entities = $this->storage->loadMultipleOriginal(); // Sort the entities using the entity class's sort() method. // See \Drupal\Core\Config\Entity\ConfigEntityBase::sort(). diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index ca6ed7a..e8e23aa 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -420,4 +420,26 @@ public function updateFromStorageRecord(ConfigEntityInterface $entity, array $va return $entity; } + /** + * {@inheritdoc} + */ + public function loadOriginal($id) { + $old_state = $this->configFactory->getOverrideState(); + $this->configFactory->setOverrideState(FALSE); + $entity = $this->load($id); + $this->configFactory->setOverrideState($old_state); + return $entity; + } + + /** + * {@inheritdoc} + */ + public function loadMultipleOriginal(array $ids = NULL) { + $old_state = $this->configFactory->getOverrideState(); + $this->configFactory->setOverrideState(FALSE); + $entities = $this->loadMultiple($ids); + $this->configFactory->setOverrideState($old_state); + return $entities; + } + } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorageInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorageInterface.php index 62c36f9..78048e4 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorageInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorageInterface.php @@ -65,4 +65,27 @@ public function createFromStorageRecord(array $values); */ public function updateFromStorageRecord(ConfigEntityInterface $entity, array $values); + /** + * Loads one entity in their original form without overrides. + * + * @param mixed $id + * The ID of the entity to load. + * + * @return \Drupal\Core\Entity\EntityInterface|null + * An entity object. NULL if no matching entity is found. + */ + public function loadOriginal($id); + + /** + * Loads one or more entities in their original form without overrides. + * + * @param $ids + * An array of entity IDs, or NULL to load all entities. + * + * @return \Drupal\Core\Entity\EntityInterface[] + * An array of entity objects indexed by their IDs. Returns an empty array + * if no matching entities found. + */ + public function loadMultipleOriginal(array $ids = NULL); + } diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueConfigEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueConfigEntityStorage.php new file mode 100644 index 0000000..3f0df02 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueConfigEntityStorage.php @@ -0,0 +1,100 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('keyvalue')->get('entity_storage__' . $entity_type->id()), + $container->get('uuid'), + $container->get('language_manager'), + $container->get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + public static function getIDFromConfigName($config_name, $config_prefix) { } + + /** + * {@inheritdoc} + */ + public function createFromStorageRecord(array $values) { } + + /** + * {@inheritdoc} + */ + public function updateFromStorageRecord(ConfigEntityInterface $entity, array $values) { } + + /** + * {@inheritdoc} + */ + public function loadOriginal($id) { + $old_state = $this->configFactory->getOverrideState(); + $this->configFactory->setOverrideState(FALSE); + $entity = $this->load($id); + $this->configFactory->setOverrideState($old_state); + return $entity; + } + + /** + * {@inheritdoc} + */ + public function loadMultipleOriginal(array $ids = NULL) { + $old_state = $this->configFactory->getOverrideState(); + $this->configFactory->setOverrideState(FALSE); + $entities = $this->loadMultiple($ids); + $this->configFactory->setOverrideState($old_state); + return $entities; + } + +} diff --git a/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php b/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php index 5ccd8ff..6f3d8e6 100644 --- a/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php +++ b/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php @@ -10,7 +10,7 @@ use Drupal\simpletest\WebTestBase; /** - * Tests that config overrides do not bleed through in entity forms. + * Tests that config overrides do not bleed through in entity forms and lists. * * @group config */ @@ -22,39 +22,50 @@ class ConfigEntityFormOverrideTest extends WebTestBase { public static $modules = array('config_test'); /** - * Tests that overrides do not affect forms. + * Tests that overrides do not affect forms or listing screens. */ public function testFormsWithOverrides() { - $overridden_name = 'Overridden label'; + $original_label = 'Default'; + $overridden_label = 'Overridden label'; + $edited_label = 'Edited label'; // Set up an override. $settings['config']['config_test.dynamic.dotted.default']['label'] = (object) array( - 'value' => $overridden_name, + 'value' => $overridden_label, 'required' => TRUE, ); $this->writeSettings($settings); - // Test that everything on the form is the same, but that the override - // worked for the config entity label. + // Test that the overridden label is loaded with the entity. + $this->assertEqual(config_test_load('dotted.default')->label(), $overridden_label); + + // Test that the original label on the listing page is intact. $this->drupalGet('admin/structure/config_test'); - $this->assertText($overridden_name); + $this->assertText($original_label); + $this->assertNoText($overridden_label); + // Test that the original label on the editing page is intact. $this->drupalGet('admin/structure/config_test/manage/dotted.default'); $elements = $this->xpath('//input[@name="label"]'); - $this->assertIdentical((string) $elements[0]['value'], 'Default'); - $this->assertNoText($overridden_name); + $this->assertIdentical((string) $elements[0]['value'], $original_label); + $this->assertNoText($overridden_label); + + // Change to a new label and test that the listing now has the edited label. $edit = array( - 'label' => 'Custom label', + 'label' => $edited_label, ); - $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('admin/structure/config_test'); - $this->assertText($overridden_name); - $this->assertNoText($edit['label']); + $this->assertNoText($overridden_label); + $this->assertText($edited_label); + // Test that the editing page now has the edited label. $this->drupalGet('admin/structure/config_test/manage/dotted.default'); $elements = $this->xpath('//input[@name="label"]'); - $this->assertIdentical((string) $elements[0]['value'], $edit['label']); + $this->assertIdentical((string) $elements[0]['value'], $edited_label); + + // Test that the overridden label is still loaded with the entity. + $this->assertEqual(config_test_load('dotted.default')->label(), $overridden_label); } } diff --git a/core/modules/system/tests/modules/keyvalue_test/keyvalue_test.module b/core/modules/system/tests/modules/keyvalue_test/keyvalue_test.module index 97d1269..74549db 100644 --- a/core/modules/system/tests/modules/keyvalue_test/keyvalue_test.module +++ b/core/modules/system/tests/modules/keyvalue_test/keyvalue_test.module @@ -11,7 +11,7 @@ function keyvalue_test_entity_type_alter(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ if (isset($entity_types['config_test'])) { - $entity_types['config_test']->setStorageClass('Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage'); + $entity_types['config_test']->setStorageClass('Drupal\Core\Entity\KeyValueStore\KeyValueConfigEntityStorage'); } if (isset($entity_types['entity_test_label'])) { $entity_types['entity_test_label']->setStorageClass('Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage');