From cf524d0172192b341f12df6d5f0c30b81d4719b1 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Wed, 11 Sep 2024 15:02:08 +0800 Subject: [PATCH] MDL-80746 gradereport_grader: fix action bar rendering This code was unnecessarily pre-rendering some context properties used by the action_menu, which also meant the mustache template expected HTML in the context, which should be avoided. Instead of pre-rendering, just export_for_template() and adjust the mustache template to render the sub template for the respective templatables. --- grade/report/grader/classes/output/action_bar.php | 15 ++++++++------- grade/report/grader/templates/action_bar.mustache | 8 +++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/grade/report/grader/classes/output/action_bar.php b/grade/report/grader/classes/output/action_bar.php index 82c82662c43..9a71f1dc2ab 100644 --- a/grade/report/grader/classes/output/action_bar.php +++ b/grade/report/grader/classes/output/action_bar.php @@ -17,7 +17,9 @@ namespace gradereport_grader\output; use core\output\comboboxsearch; +use core_course\output\actionbar\group_selector; use core_course\output\actionbar\initials_selector; +use core_course\output\actionbar\user_selector; use core_grades\output\general_action_bar; use moodle_url; @@ -70,7 +72,7 @@ class action_bar extends \core_grades\output\action_bar { * @throws \moodle_exception */ public function export_for_template(\renderer_base $output): array { - global $PAGE, $OUTPUT, $SESSION, $USER; + global $SESSION, $USER; // If in the course context, we should display the general navigation selector in gradebook. $courseid = $this->context->instanceid; // Get the data used to output the general navigation selector. @@ -94,7 +96,6 @@ class action_bar extends \core_grades\output\action_bar { $additionalparams['gpr_search'] = $this->usersearch; } - $actionbarrenderer = $PAGE->get_renderer('core_course', 'actionbar'); $initialselector = new initials_selector( course: $course, targeturl: '/grade/report/grader/index.php', @@ -102,22 +103,22 @@ class action_bar extends \core_grades\output\action_bar { lastinitial: $lastnameinitial, additionalparams: $additionalparams, ); - $data['initialselector'] = $actionbarrenderer->render($initialselector); + $data['initialselector'] = $initialselector->export_for_template($output); if ($course->groupmode) { - $data['groupselector'] = $actionbarrenderer->render( - new \core_course\output\actionbar\group_selector($this->context)); + $gs = new group_selector($this->context); + $data['groupselector'] = $gs->export_for_template($output); } $resetlink = new moodle_url('/grade/report/grader/index.php', ['id' => $courseid]); - $userselectorrenderer = new \core_course\output\actionbar\user_selector( + $userselector = new user_selector( course: $course, resetlink: $resetlink, userid: $this->userid, groupid: 0, usersearch: $this->usersearch ); - $data['searchdropdown'] = $userselectorrenderer->export_for_template($output); + $data['searchdropdown'] = $userselector->export_for_template($output); // The collapsed column dialog is aligned to the edge of the screen, we need to place it such that it also aligns. $collapsemenudirection = right_to_left() ? 'dropdown-menu-left' : 'dropdown-menu-right'; diff --git a/grade/report/grader/templates/action_bar.mustache b/grade/report/grader/templates/action_bar.mustache index efd542b8c72..c8479f05f0a 100644 --- a/grade/report/grader/templates/action_bar.mustache +++ b/grade/report/grader/templates/action_bar.mustache @@ -60,7 +60,9 @@ } ] }, - "groupselector": "
", + "searchdropdown": {"search dropdown": "context here"}, + "groupselector": {"group selector": "context here"}, + "initialselector": {"initial selector": "context here"}, "collapsedcolumns": "
", "pagereset": "http://moodle.local/grade/report/grader/index.php?id=2&userid=2&reset=1" } @@ -81,13 +83,13 @@ {{/searchdropdown}} {{#groupselector}} {{/groupselector}} {{#initialselector}} {{/initialselector}}