MDL-73532 navigation: Modify methods that extend the setting nav

Introduces some changes to the exising _extend_settings_navigation()
methods that utilize the global $PAGE object. In order to accomodate
the changes done for the secondary navigation for single activity
courses, the methods that extend the settings navigation can no longer
rely on the $PAGE object, instead the more reliabe way to obtain this
infomation is through the get_page() method from settings_navigation
class.
This commit is contained in:
Mihail Geshoski 2022-01-19 16:06:46 +08:00
parent bf27303955
commit 4a9c83ac9e
19 changed files with 132 additions and 145 deletions

View file

@ -1019,9 +1019,7 @@ function lesson_supports($feature) {
* @param settings_navigation $settings
* @param navigation_node $lessonnode
*/
function lesson_extend_settings_navigation($settings, $lessonnode) {
global $PAGE, $DB;
function lesson_extend_settings_navigation(settings_navigation $settings, navigation_node $lessonnode) {
// We want to add these new nodes after the Edit settings node, and before the
// Locally assigned roles node. Of course, both of those are controlled by capabilities.
$keys = $lessonnode->get_children_key_list();
@ -1033,17 +1031,18 @@ function lesson_extend_settings_navigation($settings, $lessonnode) {
$beforekey = $keys[$i + 1];
}
if (has_capability('mod/lesson:manageoverrides', $PAGE->cm->context)) {
$url = new moodle_url('/mod/lesson/overrides.php', array('cmid' => $PAGE->cm->id, 'mode' => 'user'));
if (has_capability('mod/lesson:manageoverrides', $settings->get_page()->cm->context)) {
$url = new moodle_url('/mod/lesson/overrides.php', ['cmid' => $settings->get_page()->cm->id, 'mode' => 'user']);
$node = navigation_node::create(get_string('overrides', 'lesson'), $url,
navigation_node::TYPE_SETTING, null, 'mod_lesson_useroverrides');
$lessonnode->add_node($node, $beforekey);
}
if (has_capability('mod/lesson:viewreports', $PAGE->cm->context)) {
if (has_capability('mod/lesson:viewreports', $settings->get_page()->cm->context)) {
$reportsnode = $lessonnode->add(
get_string('reports', 'lesson'),
new moodle_url('/mod/lesson/report.php', ['id' => $PAGE->cm->id, 'action' => 'reportoverview'])
new moodle_url('/mod/lesson/report.php', ['id' => $settings->get_page()->cm->id,
'action' => 'reportoverview'])
);
}
}