diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 8c9747a..ff99c27 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -217,14 +217,8 @@ public function save() { } } else { - // Minimal validation. Should not try to serialize resources or non-arrays. foreach ($this->data as $key => $value) { - if (is_resource($value) || (!is_scalar($value) && !is_array($value))) { - throw new UnsupportedDataTypeConfigException(String::format('Invalid data type for config element @name:@key', array( - '@name' => $this->getName(), - '@key' => $key, - ))); - } + $this->validateValue($key, $value); } } diff --git a/core/lib/Drupal/Core/Config/StorableConfigBase.php b/core/lib/Drupal/Core/Config/StorableConfigBase.php index 238cd8b..18c0f07 100644 --- a/core/lib/Drupal/Core/Config/StorableConfigBase.php +++ b/core/lib/Drupal/Core/Config/StorableConfigBase.php @@ -132,6 +132,27 @@ protected function getSchemaWrapper() { } /** + * Validate the values are allowed data types. + * + * @throws UnsupportedDataTypeConfigException + * If there is any invalid value. + */ + protected function validateValue($key, $value) { + // Minimal validation. Should not try to serialize resources or non-arrays. + if (is_array($value)) { + foreach ($value as $nested_value_key => $nested_value) { + $this->validateValue($key . '.' . $nested_value_key, $nested_value); + } + } + elseif ($value !== NULL && !is_scalar($value)) { + throw new UnsupportedDataTypeConfigException(String::format('Invalid data type for config element @name:@key', array( + '@name' => $this->getName(), + '@key' => $key, + ))); + } + } + + /** * Casts the value to correct data type using the configuration schema. * * @param string $key @@ -149,7 +170,7 @@ protected function castValue($key, $value) { if ($value === NULL) { $value = NULL; } - elseif (is_scalar($value) && !is_resource($value)) { + elseif (is_scalar($value)) { try { $element = $this->getSchemaWrapper()->get($key); if ($element instanceof PrimitiveInterface) {