Commit 205f5490 authored by catch's avatar catch

Issue #2663410 by alexpott, Berdir:...

Issue #2663410 by alexpott, Berdir: TypedConfigManager::_getDefinitionWithReplacements() incorrectly replaces generic definition
parent a55d4651
......@@ -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;
......
......@@ -542,12 +542,48 @@ public function testConfigSaveWithWrappingSchema() {
* Tests dynamic config schema type with multiple sub-key references.
*/
public function testConfigSaveWithWrappingSchemaDoubleBrackets() {
$untyped_values = [
'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');
}
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment