From 20557e9621ee2ad0c6c99fb6e51edf81e1186d37 Mon Sep 17 00:00:00 2001 From: Tamaro Walter Date: Thu, 5 Sep 2024 10:00:04 +0200 Subject: [PATCH] use right page variable --- lib.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib.php b/lib.php index 78dca56503..1f5688ca96 100644 --- a/lib.php +++ b/lib.php @@ -463,25 +463,28 @@ function moodleoverflow_pluginfile($course, $cm, $context, $filearea, $args, $fo * Extends the settings navigation with the moodleoverflow settings. * * This function is called when the context for the page is a moodleoverflow module. This is not called by AJAX - * so it is safe to rely on the $PAGE. + * so it is safe to rely on the page variable. * * @param settings_navigation $settingsnav complete settings navigation tree * @param navigation_node $moodleoverflownode moodleoverflow administration node */ function moodleoverflow_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $moodleoverflownode = null) { - global $CFG, $DB, $PAGE, $USER; + global $DB, $USER; // Retrieve the current moodle record. - $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $PAGE->cm->instance]); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $settingsnav->get_page()->cm->instance]); // Check if the user can subscribe to the instance. - $enrolled = is_enrolled($PAGE->cm->context, $USER, '', false); - $activeenrolled = is_enrolled($PAGE->cm->context, $USER, '', true); - $canmanage = has_capability('mod/moodleoverflow:managesubscriptions', $PAGE->cm->context); + if (!$context = context_module::instance($settingsnav->get_page()->cm->id)) { + throw new \moodle_exception('badcontext'); + } + $enrolled = is_enrolled($context, $USER, '', false); + $activeenrolled = is_enrolled($context, $USER, '', true); + $canmanage = has_capability('mod/moodleoverflow:managesubscriptions', $context); $forcesubscribed = \mod_moodleoverflow\subscriptions::is_forcesubscribed($moodleoverflow); $subscdisabled = \mod_moodleoverflow\subscriptions::subscription_disabled($moodleoverflow); $cansubscribe = $activeenrolled && (!$subscdisabled || $canmanage) && - !($forcesubscribed && has_capability('mod/moodleoverflow:allowforcesubscribe', $PAGE->cm->context)); + !($forcesubscribed && has_capability('mod/moodleoverflow:allowforcesubscribe', $context)); $cantrack = \mod_moodleoverflow\readtracking::moodleoverflow_can_track_moodleoverflows($moodleoverflow); // Display a link to the index. @@ -503,7 +506,7 @@ function moodleoverflow_extend_settings_navigation(settings_navigation $settings if ($cansubscribe) { // Choose the linktext depending on the current state of subscription. - $issubscribed = \mod_moodleoverflow\subscriptions::is_subscribed($USER->id, $moodleoverflow, $PAGE->cm->context); + $issubscribed = \mod_moodleoverflow\subscriptions::is_subscribed($USER->id, $moodleoverflow, $context); if ($issubscribed) { $linktext = get_string('unsubscribe', 'moodleoverflow'); } else {