diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 02afbd1..97fbb4f 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -398,12 +398,13 @@ public function castValue($value) { * Unsets value in this config object. * * @param string $key - * Name of the key whose value should be unset. + * (optional) The name of the key whose value should be unset. If omitted, + * the entire config object is emptied. * * @return Drupal\Core\Config\Config * The configuration object. */ - public function clear($key) { + public function clear($key = NULL) { if (!$this->isLoaded) { $this->load(); } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index d8e2ed5..fa90869 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -410,6 +410,10 @@ public function save(EntityInterface $entity) { $entity->preSave($this); $this->invokeHook('presave', $entity); + // Clear out any possibly existing keys in an existing configuration object, + // so any potentially stale keys are removed. + $config->clear(); + // Retrieve the desired properties and set them in config. foreach ($entity->getExportProperties() as $key => $value) { $config->set($key, $value);