Skip to content
Snippets Groups Projects
Commit 7813d65e authored by Dries Buytaert's avatar Dries Buytaert
Browse files

Issue #1940440 by vijaycs85: Fixed schema discovery to identify schema with more than one wildcard.

parent b59ad36f
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,7 @@ public function getDefinition($base_plugin_id) {
if (isset($this->definitions[$base_plugin_id])) {
$type = $base_plugin_id;
}
elseif (strpos($base_plugin_id, '.') && ($name = $this->getFallbackName($base_plugin_id)) && isset($this->definitions[$name])) {
elseif (strpos($base_plugin_id, '.') && $name = $this->getFallbackName($base_plugin_id)) {
// Found a generic name, replacing the last element by '*'.
$type = $name;
}
......@@ -95,13 +95,28 @@ protected function loadAllSchema() {
* @param string $name
* Configuration name or key.
*
* @return string
* Same name with the last part replaced by the filesystem marker.
* @return null|string
* Same name with the last part(s) replaced by the filesystem marker.
* for example, breakpoint.breakpoint.module.toolbar.narrow check for
* definition in below order:
* breakpoint.breakpoint.module.toolbar.*
* breakpoint.breakpoint.module.*.*
* breakpoint.breakpoint.*.*.*
* breakpoint.*.*.*.*
* Returns null, if no matching element.
*/
protected static function getFallbackName($name) {
$replaced = preg_replace('/\.[^.]+$/', '.' . '*', $name);
if ($replaced != $name) {
return $replaced;
protected function getFallbackName($name) {
// Check for definition of $name with filesystem marker.
$replaced = preg_replace('/(\.[^\.]+)([\.\*]*)$/', '.*\2', $name);
if ($replaced != $name ) {
if (isset($this->definitions[$replaced])) {
return $replaced;
}
else {
// No definition for this level(for example, breakpoint.breakpoint.*),
// check for next level (which is, breakpoint.*.*).
return self::getFallbackName($replaced);
}
}
}
}
......@@ -129,6 +129,24 @@ function testSchemaMapping() {
$expected['type'] = 'image.effect.image_scale';
$this->assertEqual($definition, $expected, 'Retrieved the right metadata for the first effect of image.style.medium');
// More complex, multiple filesystem marker test.
$definition = config_typed()->getDefinition('config_test.someschema.somemodule.section_one.subsection');
// This should be the schema of config_test.someschema.somemodule.*.*.
$expected = array();
$expected['label'] = 'Schema multiple filesytem marker test';
$expected['class'] = '\Drupal\Core\Config\Schema\Mapping';
$expected['mapping']['id']['type'] = 'string';
$expected['mapping']['id']['label'] = 'ID';
$expected['mapping']['description']['type'] = 'text';
$expected['mapping']['description']['label'] = 'Description';
$this->assertEqual($definition, $expected, 'Retrieved the right metadata for config_test.someschema.somemodule.section_one.subsection');
$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');
}
/**
......
testid: 'Test id'
testdescription: 'Test description'
testid: 'Test id'
testdescription: 'Test description'
......@@ -6,3 +6,14 @@ config_test.someschema:
label: "Test item"
"testlist":
label: "Test list"
config_test.someschema.somemodule.*.*:
type: mapping
label: 'Schema multiple filesytem marker test'
mapping:
id:
type: string
label: 'ID'
description:
type: text
label: 'Description'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment