diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index b2fdb0d..f9febad 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -570,7 +570,7 @@ protected function castValue($key, $value) { case 'Drupal\Core\TypedData\Plugin\DataType\Uri': case 'Drupal\Core\TypedData\Plugin\DataType\Email': case 'Drupal\Core\Config\Schema\Property': - $value = (string) $value; + $value = !isset($value) ? NULL : (string) $value; break; case 'Drupal\Core\TypedData\Plugin\DataType\Integer': if (!isset($value) || $value === '') { diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php index 8f956c9..c9bf579 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php @@ -252,6 +252,7 @@ function testSchemaData() { public function testConfigSaveWithSchema() { $untyped_values = array( 'string' => 1, + 'null_string' => '', 'integer' => '100', 'null_integer' => '', 'boolean' => 1, @@ -265,9 +266,12 @@ public function testConfigSaveWithSchema() { // Not in schema and therefore should be left untouched. 'not_present_in_schema' => TRUE, ); + $untyped_to_typed = $untyped_values; + $untyped_to_typed['null_string'] = NULL; $typed_values = array( 'string' => '1', + 'null_string' => NULL, 'integer' => 100, 'null_integer' => NULL, 'boolean' => TRUE, @@ -282,7 +286,7 @@ public function testConfigSaveWithSchema() { // Save config which has a schema that enforces types. \Drupal::config('config_test.schema_data_types') - ->setData($untyped_values) + ->setData($untyped_to_typed) ->save(); $this->assertIdentical(\Drupal::config('config_test.schema_data_types')->get(), $typed_values); diff --git a/core/modules/config/tests/config_test/config/schema/config_test.schema.yml b/core/modules/config/tests/config_test/config/schema/config_test.schema.yml index c13216d..e0377bf 100644 --- a/core/modules/config/tests/config_test/config/schema/config_test.schema.yml +++ b/core/modules/config/tests/config_test/config/schema/config_test.schema.yml @@ -106,6 +106,8 @@ config_test.schema_data_types: type: float string: type: string + null_string: + type: string boolean: type: boolean no_type: