diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index eed4f89..f78d4d7 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -581,6 +581,9 @@ protected function getSchemaWrapper() { * * @return mixed * The value cast to the type indicated in the schema. + * + * @throws \Drupal\Core\Config\UnsupportedConfigDataTypeException + * Exception on unsupported/undefined data type deducted. */ protected function castValue($key, $value) { if ($value === NULL) { @@ -616,9 +619,12 @@ protected function castValue($key, $value) { } } else { - // Any non-scalar value must be an array. + // Throw exception on any non-scalar or non-array value. if (!is_array($value)) { - $value = (array) $value; + throw new UnsupportedConfigDataTypeException(format_string('Invalid data type for config element @name:@key', array( + '@name' => $this->getName(), + '@key' => $key, + ))); } // Recurse into any nested keys. foreach ($value as $nested_value_key => $nested_value) { diff --git a/core/lib/Drupal/Core/Config/UnsupportedConfigDataTypeException.php b/core/lib/Drupal/Core/Config/UnsupportedConfigDataTypeException.php new file mode 100644 index 0000000..ac63c26 --- /dev/null +++ b/core/lib/Drupal/Core/Config/UnsupportedConfigDataTypeException.php @@ -0,0 +1,14 @@ +set('stream', fopen(__FILE__, 'r'))->save(); $this->fail('No Exception thrown upon saving invalid data type.'); } - catch (\Exception $e) { + catch (UnsupportedConfigDataTypeException $e) { $this->pass(format_string('%class thrown upon saving invalid data type.', array( '%class' => get_class($e), ))); 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 597e9f7..dbb4a37 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 @@ -131,3 +131,38 @@ config_test.schema_data_types: type: sequence sequence: - type: boolean + +config_test.types: + type: mapping + label: 'Configuration type' + mapping: + array: + type: sequence + label: 'Array' + sequence: + - type: string + label: 'Item' + boolean: + type: boolean + label: 'Boolean' + float: + type: float + label: 'Float' + exp: + type: float + label: 'Exponential' + hex: + type: integer + label: 'Hexadecimal' + int: + type: integer + label: 'Integer' + octal: + type: integer + label: 'Octal' + string: + type: string + label: 'String' + string_int: + type: string + label: 'String integer'