diff -u b/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php --- b/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -302,24 +302,18 @@ * Unsets value in this config object. * * @param string $key - * (optional) The name of the key whose value should be unset. If omitted, - * the entire config object is emptied. + * Name of the key whose value should be unset. * * @return Drupal\Core\Config\Config * The configuration object. */ - public function clear($key = NULL) { - if (!isset($key)) { - $this->data = array(); + public function clear($key) { + $parts = explode('.', $key); + if (count($parts) == 1) { + unset($this->data[$key]); } else { - $parts = explode('.', $key); - if (count($parts) == 1) { - unset($this->data[$key]); - } - else { - NestedArray::unsetValue($this->data, $parts); - } + NestedArray::unsetValue($this->data, $parts); } $this->resetOverriddenData(); return $this; reverted: --- b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -274,10 +274,6 @@ $this->preSave($entity); $this->invokeHook('presave', $entity); - // Clear out any possibly existing keys in an existing configuration object, - // so any potentially stale keys are removed. - $config->clear(); - // Configuration objects do not have a schema. Extract all key names from // class properties. $class_info = new \ReflectionClass($entity); diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php @@ -93,9 +93,9 @@ } /** - * Tests key injection order. + * Tests Drupal\Core\Config\Config::sortByKey(). */ - function testDataKeySort() { + function testDataKeyOrderPreservation() { $config = config('config_test.keysort'); $config->set('new', 'Value to be replaced'); $config->set('static', 'static'); @@ -107,13 +107,15 @@ // Load the configuration data into a new object. $new_config = config('config_test.keysort'); + // Clear the 'new' key that came first. + $new_config->clear('new'); // Add a new 'new' key and save. $new_config->set('new', 'Value to be replaced'); $new_config->save(); - // Verify that the data of both objects is in the identical order. + // Verify that the data of objects is in the opposite order. // assertIdentical() is the required essence of this test; it performs a // strict comparison, which means that keys and values must be identical and // their order must be identical. - $this->assertIdentical($new_config->get(), $config->get()); + $this->assertIdentical($new_config->get(), array_reverse($config->get())); } } reverted: --- b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -85,19 +85,6 @@ $this->assertResponse(200); $this->assertNoText($label1); $this->assertText($label3); - $id = $edit['id']; - - // Add an orphan key to the configuration entity's object. - $config = config('config_test.dynamic.' . $id); - $config->set('foo', 'bar')->save(); - - // Re-save the configuration entity. - $this->drupalPost('admin/structure/config_test/manage/' . $id, array(), 'Save'); - $this->assertResponse(200); - - // Verify that the orphan key was destroyed. - $config = config('config_test.dynamic.' . $id); - $this->assertNull($config->get('foo')); } }