Skip to content

Commit

Permalink
MDL-64757 core_output: fixed incorrect string language mustache blocks
Browse files Browse the repository at this point in the history
Mustache blocks nested in parent templates were incorrectly rendering the default language Moodle.
This fix correctly passes the current language preference to all nested mustache templates such as blocks
which are children of another template.
  • Loading branch information
Tom Dickman committed Jul 26, 2019
1 parent 1a89704 commit ad5c8a8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/classes/output/mustache_template_source_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function load_with_dependencies(
// Get the requested template source.
$templatesource = $this->load($templatecomponent, $templatename, $themename, $includecomments);
// This is a helper function to save a value in one of the result arrays (either $templates or $strings).
$save = function(array $results, array $seenlist, string $component, string $id, $value) {
$save = function(array $results, array $seenlist, string $component, string $id, $value) use ($lang) {
if (!isset($results[$component])) {
// If the results list doesn't already contain this component then initialise it.
$results[$component] = [];
Expand All @@ -173,7 +173,7 @@ public function load_with_dependencies(
};
// This is a helper function for processing a dependency. Does stuff like ignore duplicate processing,
// common result formatting etc.
$handler = function(array $dependency, array $ignorelist, callable $processcallback) {
$handler = function(array $dependency, array $ignorelist, callable $processcallback) use ($lang) {
foreach ($dependency as $component => $ids) {
foreach ($ids as $id) {
$dependencyid = "$component/$id";
Expand Down Expand Up @@ -223,7 +223,8 @@ function($component, $id) use (
&$seenstrings,
&$templates,
&$strings,
$save
$save,
$lang
) {
// We haven't seen this template yet so load it and it's dependencies.
$subdependencies = $this->load_with_dependencies(
Expand All @@ -232,7 +233,8 @@ function($component, $id) use (
$themename,
$includecomments,
$seentemplates,
$seenstrings
$seenstrings,
$lang
);

foreach ($subdependencies['templates'] as $component => $ids) {
Expand Down

0 comments on commit ad5c8a8

Please sign in to comment.