Commit 44c83898 authored by catch's avatar catch

Issue #1972816 by yched | vijaycs85: Fixed Add support for %parent.%parent in...

Issue #1972816 by yched | vijaycs85: Fixed Add support for %parent.%parent in config schema dynamic type names.
parent e1c40673
......@@ -85,7 +85,7 @@ public function create(array $definition, $value = NULL, $name = NULL, $parent =
// Replace variable names in definition.
$replace = is_array($value) ? $value : array();
if (isset($parent)) {
$replace['%parent'] = $parent->getValue();
$replace['%parent'] = $parent;
}
if (isset($name)) {
$replace['%key'] = $name;
......@@ -268,7 +268,19 @@ protected function replaceVariable($value, $data) {
}
else {
// Get nested value and continue processing.
$data = $data[$name];
if ($name == '%parent') {
// Switch replacement values with values from the parent.
$parent = $data['%parent'];
$data = $parent->getValue();
// The special %parent and %key values now need to point one level up.
if ($new_parent = $parent->getParent()) {
$data['%parent'] = $new_parent;
$data['%key'] = $new_parent->getName();
}
}
else {
$data = $data[$name];
}
}
}
}
......
......@@ -154,7 +154,43 @@ function testSchemaMapping() {
$definition = config_typed()->getDefinition('config_test.someschema.somemodule.section_two.subsection');
// The other file should have the same schema.
$this->assertEqual($definition, $expected, 'Retrieved the right metadata for config_test.someschema.somemodule.section_two.subsection');
}
/**
* Tests metadata retrieval with several levels of %parent indirection.
*/
function testSchemaMappingWithParents() {
$config_data = config_typed()->get('config_test.someschema.with_parents');
// Test fetching parent one level up.
$entry = $config_data->get('one_level');
$definition = $entry['testitem']->getDefinition();
$expected = array(
'type' => 'config_test.someschema.with_parents.key_1',
'label' => 'Test item nested one level',
'class' => '\Drupal\Core\TypedData\Plugin\DataType\String',
);
$this->assertEqual($definition, $expected);
// Test fetching parent two levels up.
$entry = $config_data->get('two_levels');
$definition = $entry['wrapper']['testitem']->getDefinition();
$expected = array(
'type' => 'config_test.someschema.with_parents.key_2',
'label' => 'Test item nested two levels',
'class' => '\Drupal\Core\TypedData\Plugin\DataType\String',
);
$this->assertEqual($definition, $expected);
// Test fetching parent three levels up.
$entry = $config_data->get('three_levels');
$definition = $entry['wrapper_1']['wrapper_2']['testitem']->getDefinition();
$expected = array(
'type' => 'config_test.someschema.with_parents.key_3',
'label' => 'Test item nested three levels',
'class' => '\Drupal\Core\TypedData\Plugin\DataType\String',
);
$this->assertEqual($definition, $expected);
}
/**
......
one_level:
target_key: key_1
testitem: "text for entry_1"
two_levels:
target_key: key_2
wrapper:
testitem: "text for entry_2"
three_levels:
target_key: key_3
wrapper_1:
wrapper_2:
testitem: "text for entry_3"
......@@ -7,6 +7,60 @@ config_test.someschema:
"testlist":
label: "Test list"
config_test.someschema.with_parents:
label: "Schema test data with parenting"
type: mapping
mapping:
one_level:
label: "Parenting one level up"
type: mapping
mapping:
target_key:
label: "Key used in parent relation"
type: string
testitem:
type: config_test.someschema.with_parents.[%parent.target_key]
two_levels:
label: "Parenting two levels up"
type: mapping
mapping:
target_key:
label: "Key used in parent relation"
type: string
wrapper:
label: "Wrapper"
type: mapping
mapping:
testitem:
type: config_test.someschema.with_parents.[%parent.%parent.target_key]
three_levels:
label: "Parenting three levels up"
type: mapping
mapping:
target_key:
label: "Key used in parent relation"
type: string
wrapper_1:
label: "Wrapper 1"
type: mapping
mapping:
wrapper_2:
label: "Wrapper 2"
type: mapping
mapping:
testitem:
type: config_test.someschema.with_parents.[%parent.%parent.%parent.target_key]
config_test.someschema.with_parents.key_1:
label: "Test item nested one level"
type: string
config_test.someschema.with_parents.key_2:
label: "Test item nested two levels"
type: string
config_test.someschema.with_parents.key_3:
label: "Test item nested three levels"
type: string
config_test.someschema.somemodule.*.*:
type: mapping
label: 'Schema multiple filesytem marker test'
......
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