diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index c7d378e..b2fdb0d 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -573,13 +573,23 @@ protected function castValue($key, $value) { $value = (string) $value; break; case 'Drupal\Core\TypedData\Plugin\DataType\Integer': - $value = (int) $value; + if (!isset($value) || $value === '') { + $value = NULL; + } + else { + $value = (int) $value; + } break; case 'Drupal\Core\TypedData\Plugin\DataType\Boolean': $value = (bool) $value; break; case 'Drupal\Core\TypedData\Plugin\DataType\Float': - $value = (float) $value; + if (!isset($value) || $value === '') { + $value = NULL; + } + else { + $value = (float) $value; + } break; default: // Don't change the value. diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php index 84a97f2..8f956c9 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php @@ -253,6 +253,7 @@ public function testConfigSaveWithSchema() { $untyped_values = array( 'string' => 1, 'integer' => '100', + 'null_integer' => '', 'boolean' => 1, // In the config schema this doesn't have a type so should cast to string. 'no_type' => 1, @@ -260,6 +261,7 @@ public function testConfigSaveWithSchema() { 'string' => 1 ), 'float' => '3.14', + 'null_float' => '', // Not in schema and therefore should be left untouched. 'not_present_in_schema' => TRUE, ); @@ -267,12 +269,14 @@ public function testConfigSaveWithSchema() { $typed_values = array( 'string' => '1', 'integer' => 100, + 'null_integer' => NULL, 'boolean' => TRUE, 'no_type' => '1', 'array' => array( 'string' => '1' ), 'float' => 3.14, + 'null_float' => NULL, 'not_present_in_schema' => TRUE, ); 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 d9851c3..c13216d 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 @@ -98,8 +98,12 @@ config_test.schema_data_types: mapping: integer: type: integer + null_integer: + type: integer float: type: float + null_float: + type: float string: type: string boolean: diff --git a/core/modules/number/config/schema/number.schema.yml b/core/modules/number/config/schema/number.schema.yml index 9aafca5..f597c02 100644 --- a/core/modules/number/config/schema/number.schema.yml +++ b/core/modules/number/config/schema/number.schema.yml @@ -12,10 +12,10 @@ field.number_integer.instance_settings: label: 'Integer' mapping: min: - type: string + type: integer label: 'Minimum' max: - type: string + type: integer label: 'Maximum' prefix: type: string @@ -51,10 +51,10 @@ field.number_decimal.instance_settings: label: 'Decimal' mapping: min: - type: string + type: float label: 'Minimum' max: - type: string + type: float label: 'Maximum' prefix: type: string @@ -71,7 +71,7 @@ field.number_decimal.value: label: 'Default value' mapping: value: - type: string + type: float label: 'Value' field.number_float.settings: @@ -86,10 +86,10 @@ field.number_float.instance_settings: label: 'Float' mapping: min: - type: string + type: float label: 'Minimum' max: - type: string + type: float label: 'Maximum' prefix: type: string @@ -106,5 +106,5 @@ field.number_float.value: label: 'Default value' mapping: value: - type: string + type: float label: 'Value'