diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index c9084b7..18afe28 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -426,7 +426,7 @@ public function save() { // conform to the schema. if ($this->getTypedConfigManager()->hasConfigSchema($this->name)) { // Ensure that the schema wrapper has the latest data. - $this->setSchemaWrapper(); + $this->schemaWrapper = NULL; foreach ($this->data as $key => $value) { $this->data[$key] = $this->castValue($key, $value); } @@ -498,29 +498,22 @@ public function merge(array $data_to_merge) { /** * Gets the schema wrapper for the whole configuration object. * + * The schema wrapper is dependent on the configuration name and the whole + * data structure, so if the name or the data changes in any way, the wrapper + * should be reset. + * * @return \Drupal\Core\Config\Schema\Element */ protected function getSchemaWrapper() { - if (empty($this->schemaWrapper)) { - $this->setSchemaWrapper(); + if (!isset($this->schemaWrapper)) { + $typed_config_manager = $this->getTypedConfigManager(); + $definition = $typed_config_manager->getDefinition($this->name); + $this->schemaWrapper = $typed_config_manager->create($definition, $this->data); } return $this->schemaWrapper; } /** - * Sets the schema wrapper property using the current configuration data. - * - * @return \Drupal\Core\Config\Config - * The configuration object. - */ - protected function setSchemaWrapper() { - $typed_config_manager = $this->getTypedConfigManager(); - $definition = $typed_config_manager->getDefinition($this->name); - $this->schemaWrapper = $typed_config_manager->create($definition, $this->data); - return $this; - } - - /** * Gets the definition for the configuration key. * * @param string $key @@ -582,6 +575,9 @@ protected function castValue($key, $value) { case 'Drupal\Core\TypedData\Plugin\DataType\Boolean': $value = (bool) $value; break; + case 'Drupal\Core\TypedData\Plugin\DataType\Float': + $value = (float) $value; + break; default: // Don't change the value. break; @@ -610,7 +606,7 @@ protected function castValue($key, $value) { * @return \Drupal\Core\Config\TypedConfigManager */ protected function getTypedConfigManager() { - if (empty($this->typedConfigManager)) { + if (!isset($this->typedConfigManager)) { $this->typedConfigManager = \Drupal::service('config.typed'); } return $this->typedConfigManager; diff --git a/core/lib/Drupal/Core/Config/Schema/Mapping.php b/core/lib/Drupal/Core/Config/Schema/Mapping.php index 72de972..92e9a90 100644 --- a/core/lib/Drupal/Core/Config/Schema/Mapping.php +++ b/core/lib/Drupal/Core/Config/Schema/Mapping.php @@ -27,7 +27,7 @@ class Mapping extends ArrayElement implements ComplexDataInterface { protected function parse() { $elements = array(); foreach ($this->definition['mapping'] as $key => $definition) { - if (array_key_exists($key, $this->value)) { + if (isset($this->value[$key]) || array_key_exists($key, $this->value)) { $elements[$key] = $this->parseElement($key, $this->value[$key], $definition); } } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php index a2b7db1..9f465d7 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php @@ -259,6 +259,7 @@ public function testConfigSaveWithSchema () { 'array' => array( 'string' => 1 ), + 'float' => '3.14', // Not in schema and therefore should be left untouched. 'not_present_in_schema' => TRUE, ); @@ -271,6 +272,7 @@ public function testConfigSaveWithSchema () { 'array' => array( 'string' => '1' ), + 'float' => 3.14, '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 faba694..d9851c3 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,6 +98,8 @@ config_test.schema_data_types: mapping: integer: type: integer + float: + type: float string: type: string boolean: