diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index bdeeba1..b3b51c2 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -110,7 +110,7 @@ public function get($key = '') { * {@inheritdoc} */ public function setData(array $data) { - $this->data = $data; + parent::setData($data); $this->resetOverriddenData(); return $this; } diff --git a/core/lib/Drupal/Core/Config/ConfigBase.php b/core/lib/Drupal/Core/Config/ConfigBase.php index b0db1b6..37e0d80 100644 --- a/core/lib/Drupal/Core/Config/ConfigBase.php +++ b/core/lib/Drupal/Core/Config/ConfigBase.php @@ -161,7 +161,7 @@ public function get($key = '') { * @return $this * The configuration object. * - * @throws \Exception + * @throws \Drupal\Core\Config\ConfigValueException * If any key in $data in any depth contains a dot. */ public function setData(array $data) { @@ -178,13 +178,13 @@ public function setData(array $data) { * * @return null * - * @throws \Exception + * @throws \Drupal\Core\Config\ConfigValueException * If any key in $data in any depth contains a dot. */ protected function validateKeys(array $data) { foreach ($data as $key => $value) { if (strpos($key, '.') !== FALSE) { - throw new \Exception(String::format('@key key contains a dot which is not supported.', array('@key' => $key))); + throw new ConfigValueException(String::format('@key key contains a dot which is not supported.', array('@key' => $key))); } if (is_array($value)) { $this->validateKeys($value); @@ -203,7 +203,7 @@ protected function validateKeys(array $data) { * @return $this * The configuration object. * - * @throws \Exception + * @throws \Drupal\Core\Config\ConfigValueException * If $value is an array and any of its keys in any depth contains a dot. */ public function set($key, $value) { diff --git a/core/modules/config/src/Tests/ConfigCRUDTest.php b/core/modules/config/src/Tests/ConfigCRUDTest.php index dc6de36..5358c06 100644 --- a/core/modules/config/src/Tests/ConfigCRUDTest.php +++ b/core/modules/config/src/Tests/ConfigCRUDTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigNameException; +use Drupal\Core\Config\ConfigValueException; use Drupal\Core\Config\InstallStorage; use Drupal\simpletest\DrupalUnitTestBase; use Drupal\Core\Config\FileStorage; @@ -190,6 +191,31 @@ function testNameValidation() { } /** + * Tests the validation of configuration object values. + */ + function testValueValidation() { + // Verify that setData() will catch dotted keys. + $message = 'Expected ConfigValueException was thrown from setData() for value with dotted keys.'; + try { + \Drupal::config('namespace.object')->setData(array('key.value' => 12))->save(); + $this->fail($message); + } + catch (ConfigValueException $e) { + $this->pass($message); + } + + // Verify that set() will catch dotted keys. + $message = 'Expected ConfigValueException was thrown from set() for value with dotted keys.'; + try { + \Drupal::config('namespace.object')->set('foo', array('key.value' => 12))->save(); + $this->fail($message); + } + catch (ConfigValueException $e) { + $this->pass($message); + } + } + + /** * Tests data type handling. */ public function testDataTypes() { diff --git a/core/lib/Drupal/Core/Config/ConfigValueException.php b/core/lib/Drupal/Core/Config/ConfigValueException.php new file mode 100644 index 0000000..9802228 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigValueException.php @@ -0,0 +1,13 @@ +