MDL-70486 output: Improve check for block region name string existence

* The fact that non-existing strings are returned in certain format
  starting with the bracket, is kind of side debugging effect. The value
  is really undefined and should not be relied upon.
* The string could actually exist and be worded so that its first
  character is also the square bracket.
This commit is contained in:
David Mudrák 2020-12-16 20:50:06 +01:00
parent f34b44674f
commit f00ad20a6f
2 changed files with 22 additions and 10 deletions

View File

@ -2451,22 +2451,22 @@ class theme_config {
* @return string
*/
protected function get_region_name($region, $theme) {
$regionstring = get_string('region-' . $region, 'theme_' . $theme);
// A name exists in this theme, so use it
if (substr($regionstring, 0, 1) != '[') {
return $regionstring;
$stringman = get_string_manager();
// Check if the name is defined in the theme.
if ($stringman->string_exists('region-' . $region, 'theme_' . $theme)) {
return get_string('region-' . $region, 'theme_' . $theme);
}
// Otherwise, try to find one elsewhere
// Check parents, if any
// Check the theme parents.
foreach ($this->parents as $parentthemename) {
$regionstring = get_string('region-' . $region, 'theme_' . $parentthemename);
if (substr($regionstring, 0, 1) != '[') {
return $regionstring;
if ($stringman->string_exists('region-' . $region, 'theme_' . $parentthemename)) {
return get_string('region-' . $region, 'theme_' . $parentthemename);
}
}
// Last resort, try the boost theme for names
// Last resort, try the boost theme for names.
return get_string('region-' . $region, 'theme_boost');
}

View File

@ -213,4 +213,16 @@ class core_theme_config_testcase extends advanced_testcase {
$this->assertEquals($cssexpected, $cssactual);
}
/**
* Test that {@see theme_config::get_all_block_regions()} returns localised list of region names.
*/
public function test_get_all_block_regions() {
$this->resetAfterTest();
$theme = theme_config::load(theme_config::DEFAULT_THEME);
$regions = $theme->get_all_block_regions();
$this->assertEquals('Right', $regions['side-pre']);
}
}