diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 51d3686363..91d7695006 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -304,7 +304,7 @@ public function getOriginal($key = '', $apply_overrides = TRUE) { } /** - * Determines if there are overrides applied to this configuration object. + * Determines if overrides are applied to a key for this configuration object. * * @param string $key * A string that maps to a key within the configuration data. @@ -317,10 +317,10 @@ public function hasOverrides($key = '') { $parts = explode('.', $key); $override_exists = FALSE; if (isset($this->moduleOverrides) && is_array($this->moduleOverrides)) { - $override_exists = NestedArray::keyExists($this->moduleOverrides, $parts); + $override_exists = NestedArray::keyExists($this->moduleOverrides, $parts); } if (!$override_exists && isset($this->settingsOverrides) && is_array($this->settingsOverrides)) { - $override_exists = NestedArray::keyExists($this->settingsOverrides, $parts); + $override_exists = NestedArray::keyExists($this->settingsOverrides, $parts); } return $override_exists; } diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index 3ecbb47598..d5b71edc07 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -524,6 +524,34 @@ public function overrideDataProvider() { ], ], ], + [ + // Original data. + [ + 'a' => [ + 'b' => 'originalValue' + ], + ], + // Module overrides. + [ + 'a' => [ + 'b' => 'moduleValue' + ], + ], + // Setting overrides. + [], + ], + [ + // Original data. + [ + 'a' => [ + 'b' => 'originalValue' + ], + ], + // Module overrides. + [], + // Setting overrides. + [], + ], ]; } @@ -646,6 +674,11 @@ protected function assertOverriddenKeys(array $data, array $overridden_data = [] $non_overridden_keys = array_diff(array_keys($data), array_keys($overridden_data)); foreach ($non_overridden_keys as $non_overridden_key) { $this->assertFalse($this->config->hasOverrides($non_overridden_key)); + // If there are nested overrides test a combined key also. + if (is_array($overridden_data)) { + $nested_non_overridden_key = $non_overridden_key . '.' . key($overridden_data); + $this->assertFalse($this->config->hasOverrides($nested_non_overridden_key)); + } } }