]> git.mjollnir.org Git - moodle.git/commitdiff
navigation MDL-20735 Fixed bug that caused exception when modules were added to the...
authorSam Hemelryk <sam@moodle.com>
Wed, 4 Nov 2009 01:45:55 +0000 (01:45 +0000)
committerSam Hemelryk <sam@moodle.com>
Wed, 4 Nov 2009 01:45:55 +0000 (01:45 +0000)
lib/navigationlib.php

index 86e07f416daa6e05944742fbb9656829d5caaef8..f2916b13fc68f872971f4fb552405639ce46309e 100644 (file)
@@ -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)) {