diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index 36ff68b..1181953 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -174,8 +174,8 @@ protected function getDefinitionWithReplacements($base_plugin_id, array $replace // Merge the newly determined subtype definition with the original // definition. $definition = NestedArray::mergeDeepArray([$definitions[$sub_type], $definition], TRUE); + $type = "$type||$sub_type"; } - // Unset type so we try the merge only once per type. unset($definition['type']); $this->definitions[$type] = $definition; diff --git a/core/modules/config/src/Tests/ConfigSchemaTest.php b/core/modules/config/src/Tests/ConfigSchemaTest.php index 74e543b..a89db0e 100644 --- a/core/modules/config/src/Tests/ConfigSchemaTest.php +++ b/core/modules/config/src/Tests/ConfigSchemaTest.php @@ -546,8 +546,44 @@ public function testConfigSaveWithWrappingSchemaDoubleBrackets() { 'tests' => [ [ 'wrapper_value' => 'foo', + 'foo' => 'turtle', + 'bar' => 'horse', + // Converted to a string by 'test.double_brackets.turtle.horse' + // schema. + 'another_key' => '100', + ], + ], + ]; + + $typed_values = [ + 'tests' => [ + [ + 'wrapper_value' => 'foo', + 'foo' => 'turtle', + 'bar' => 'horse', + 'another_key' => 100, + ], + ], + ]; + + // Save config which has a schema that enforces types. + \Drupal::configFactory()->getEditable('wrapping.config_schema_test.double_brackets') + ->setData($untyped_values) + ->save(); + $this->assertIdentical(\Drupal::config('wrapping.config_schema_test.double_brackets') + ->get(), $typed_values); + + $tests = \Drupal::service('config.typed')->get('wrapping.config_schema_test.double_brackets')->get('tests')->getElements(); + $definition = $tests[0]->getDataDefinition()->toArray(); + $this->assertEqual($definition['type'], 'wrapping.test.double_brackets.*||test.double_brackets.turtle.horse'); + + $untyped_values = [ + 'tests' => [ + [ + 'wrapper_value' => 'foo', 'foo' => 'cat', 'bar' => 'dog', + // Converted to a string by 'test.double_brackets.cat.dog' schema. 'another_key' => 100, ], ], @@ -570,6 +606,36 @@ public function testConfigSaveWithWrappingSchemaDoubleBrackets() { ->save(); $this->assertIdentical(\Drupal::config('wrapping.config_schema_test.double_brackets') ->get(), $typed_values); + + $tests = \Drupal::service('config.typed')->get('wrapping.config_schema_test.double_brackets')->get('tests')->getElements(); + $definition = $tests[0]->getDataDefinition()->toArray(); + $this->assertEqual($definition['type'], 'wrapping.test.double_brackets.*||test.double_brackets.cat.dog'); + + // Combine everything in a single save. + $typed_values = [ + 'tests' => [ + [ + 'wrapper_value' => 'foo', + 'foo' => 'cat', + 'bar' => 'dog', + 'another_key' => 100, + ], + [ + 'wrapper_value' => 'foo', + 'foo' => 'turtle', + 'bar' => 'horse', + 'another_key' => '100', + ], + ], + ]; + \Drupal::configFactory()->getEditable('wrapping.config_schema_test.double_brackets') + ->setData($typed_values) + ->save(); + $tests = \Drupal::service('config.typed')->get('wrapping.config_schema_test.double_brackets')->get('tests')->getElements(); + $definition = $tests[0]->getDataDefinition()->toArray(); + $this->assertEqual($definition['type'], 'wrapping.test.double_brackets.*||test.double_brackets.cat.dog'); + $definition = $tests[1]->getDataDefinition()->toArray(); + $this->assertEqual($definition['type'], 'wrapping.test.double_brackets.*||test.double_brackets.turtle.horse'); } } diff --git a/core/modules/config/tests/config_schema_test/config/schema/config_schema_test.schema.yml b/core/modules/config/tests/config_schema_test/config/schema/config_schema_test.schema.yml index d7ec9a5..f96bb8b 100644 --- a/core/modules/config/tests/config_schema_test/config/schema/config_schema_test.schema.yml +++ b/core/modules/config/tests/config_schema_test/config/schema/config_schema_test.schema.yml @@ -258,5 +258,15 @@ test.double_brackets.cat.dog: bar: type: string +test.double_brackets.turtle.horse: + type: test.double_brackets + mapping: + another_key: + type: integer + foo: + type: string + bar: + type: string + test.double_brackets.*: type: mapping