diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 034dff18fd9ad168faffc1004db2792a437ef6a1..3fe956355aeb34798b3372a105a1afb92d6cdfd9 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -270,13 +270,14 @@ public function set($key, $value) { * Any non-scalar value that is not an array (aka objects) gets cast * to an array. * - * @param $value + * @param mixed $value * A value being saved into the configuration system. - * @param $value + * + * @return string * The value cast to a string or array. */ public function castValue($value) { - if (is_scalar($value)) { + if (is_scalar($value) || $value === NULL) { // Handle special case of FALSE, which should be '0' instead of ''. if ($value === FALSE) { $value = '0'; diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigFileContentTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigFileContentTest.php index 79d7881b109c86b2bb7cda8b4ca7a255a30c12a0..b3eea4369579d4e0a81906a62cebb5226ed8241e 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigFileContentTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigFileContentTest.php @@ -84,6 +84,9 @@ function testReadWriteConfig() { // Add a boolean true value. Should get cast to 1 $config->set($true_key, TRUE); + // Add a null value. Should get cast to an empty string. + $config->set('null', NULL); + // Add an array with a nested boolean false that should get cast to 0. $config->set($casting_array_key, $casting_array_value); $config->save(); @@ -119,6 +122,9 @@ function testReadWriteConfig() { // Read true value $this->assertEqual($config->get($true_key), '1', format_string("Boolean TRUE value returned the string '1'.")); + // Read null value. + $this->assertIdentical($config->get('null'), ''); + // Read false that had been nested in an array value $this->assertEqual($config->get($casting_array_false_value_key), '0', format_string("Nested boolean FALSE value returned the string '0'."));