From 7eef78def5ead4e7e697697704cef40bb587c181 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Wed, 4 Nov 2009 01:45:55 +0000 Subject: [PATCH] navigation MDL-20735 Fixed bug that caused exception when modules were added to the front page --- lib/navigationlib.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 86e07f416d..f2916b13fc 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1213,9 +1213,12 @@ class global_navigation extends navigation_node { global $DB, $CFG, $PAGE; if (!$PAGE->cm && $this->context->contextlevel == CONTEXT_MODULE && $this->context->instanceid) { - $cm = get_coursemodule_from_id('chat', $this->context->instanceid); - $cm->context = $this->context; + // This is risky but we have no other choice... we need that module and the module + // itself hasn't set PAGE->cm (usually set by require_login) + // Chances are this is a front page module. + $cm = get_coursemodule_from_id(false, $this->context->instanceid); if ($cm) { + $cm->context = $this->context; $PAGE->set_cm($cm, $PAGE->course); } else { debugging('The module has not been set against the page but we are attempting to generate module specific information for navigation', DEBUG_DEVELOPER); @@ -1233,7 +1236,12 @@ class global_navigation extends navigation_node { $node = $this->find_child($PAGE->cm->id, self::TYPE_ACTIVITY); if ($node) { $node->make_active(); - $this->context = $PAGE->course->context; + if (!isset($PAGE->course->context)) { + // If we get here chances we are on a front page module + $this->context = $PAGE->context; + } else { + $this->context = $PAGE->course->context; + } $file = $CFG->dirroot.'/mod/'.$module->name.'/lib.php'; $function = $module->name.'_extend_navigation'; if (file_exists($file)) { -- 2.39.5