Commit 1fbdcc7a authored by alexpott's avatar alexpott
Browse files

Issue #2693081 by yanniboi, YesCT: Merging data types leads to incomplete definition

parent bfaf6b6e
......@@ -166,9 +166,14 @@ protected function getDefinitionWithReplacements($base_plugin_id, array $replace
// Replace dynamic portions of the definition type.
if (!empty($replacements) && strpos($definition['type'], ']')) {
$sub_type = $this->determineType($this->replaceName($definition['type'], $replacements), $definitions);
$sub_definition = $definitions[$sub_type];
if (isset($definitions[$sub_type]['type'])) {
$sub_merge = $this->getDefinition($definitions[$sub_type]['type'], $exception_on_invalid);
$sub_definition = NestedArray::mergeDeepArray([$sub_merge, $definitions[$sub_type]], TRUE);
}
// Merge the newly determined subtype definition with the original
// definition.
$definition = NestedArray::mergeDeepArray([$definitions[$sub_type], $definition], TRUE);
$definition = NestedArray::mergeDeepArray([$sub_definition, $definition], TRUE);
$type = "$type||$sub_type";
}
// Unset type so we try the merge only once per type.
......
......@@ -270,3 +270,30 @@ test.double_brackets.turtle.horse:
test.double_brackets.*:
type: mapping
wrapping.config_schema_test.other_double_brackets:
type: config_object
mapping:
tests:
type: sequence
sequence:
- type: wrapping.test.other_double_brackets.[id]
wrapping.test.other_double_brackets.*:
type: test.double_brackets.[id]
mapping:
id:
type: string
foo:
type: string
bar:
type: string
test.double_brackets.cat:*.*:
type: test.double_brackets.breed
test.double_brackets.breed:
type: test.double_brackets
mapping:
breed:
type: string
......@@ -631,6 +631,27 @@ public function testConfigSaveWithWrappingSchemaDoubleBrackets() {
$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');
$typed_values = [
'tests' => [
[
'id' => 'cat:persion.dog',
'foo' => 'cat',
'bar' => 'dog',
'breed' => 'persion',
],
],
];
\Drupal::configFactory()->getEditable('wrapping.config_schema_test.other_double_brackets')
->setData($typed_values)
->save();
$tests = \Drupal::service('config.typed')->get('wrapping.config_schema_test.other_double_brackets')->get('tests')->getElements();
$definition = $tests[0]->getDataDefinition()->toArray();
// Check that definition type is a merge of the expected types.
$this->assertEqual($definition['type'], 'wrapping.test.other_double_brackets.*||test.double_brackets.cat:*.*');
// Check that breed was inherited from parent definition.
$this->assertEqual($definition['mapping']['breed'], ['type' => 'string']);
}
}
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