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..fb61301 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorageInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorageInterface.php @@ -65,4 +65,28 @@ 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/modules/config/src/Tests/ConfigEntityFormOverrideTest.php b/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php index 5ccd8ff..4c097f7 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,56 @@ 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 used on a regular page. + $this->drupalGet('config_test/dotted.default'); + $this->assertText($overridden_label); + $this->assertNoText($original_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 used on a regular page regardless of + // the change to the label on the edit form. + $this->drupalGet('config_test/dotted.default'); + $this->assertText($overridden_label); + $this->assertNoText($original_label); + $this->assertNoText($edited_label); } } diff --git a/core/modules/config/tests/config_test/config_test.routing.yml b/core/modules/config/tests/config_test/config_test.routing.yml index 3a96481..1695459 100644 --- a/core/modules/config/tests/config_test/config_test.routing.yml +++ b/core/modules/config/tests/config_test/config_test.routing.yml @@ -59,6 +59,13 @@ entity.config_test.delete_form_config_test_no_status: requirements: _access: 'TRUE' +config_test.page: + path: '/config_test/{config_test}' + defaults: + _controller: '\Drupal\config_test\ConfigTestController::page' + requirements: + _access: 'TRUE' + config_test.schema_listener: path: '/config_test/schema_listener' defaults: diff --git a/core/modules/config/tests/config_test/src/ConfigTestController.php b/core/modules/config/tests/config_test/src/ConfigTestController.php index cb62642..5150f67 100644 --- a/core/modules/config/tests/config_test/src/ConfigTestController.php +++ b/core/modules/config/tests/config_test/src/ConfigTestController.php @@ -18,6 +18,19 @@ class ConfigTestController extends ControllerBase { /** + * Route callback. + * + * @param \Drupal\config_test\Entity\ConfigTest $config_test + * The ConfigTest object. + * + * @return string + * The label of the ConfigTest object. + */ + public function page(ConfigTest $config_test) { + return $config_test->label(); + } + + /** * Route title callback. * * @param \Drupal\config_test\Entity\ConfigTest $config_test