navigation MDL-20735 Fixed issue with unset cm contexts for front page course
authorSam Hemelryk <sam@moodle.com>
Thu, 10 Dec 2009 03:33:30 +0000 (03:33 +0000)
committerSam Hemelryk <sam@moodle.com>
Thu, 10 Dec 2009 03:33:30 +0000 (03:33 +0000)
lib/navigationlib.php

index 8b298a3..5f2c29a 100644 (file)
@@ -1281,6 +1281,11 @@ class global_navigation extends navigation_node {
             }
             $file = $CFG->dirroot.'/mod/'.$module->name.'/lib.php';
             $function = $module->name.'_extend_navigation';
+
+            if (empty($PAGE->cm->context)) {
+                $PAGE->cm->context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->instance);
+            }
+
             if (file_exists($file)) {
                 require_once($file);
                 if (function_exists($function)) {
@@ -2940,6 +2945,14 @@ class settings_navigation extends navigation_node {
             return;
         }
 
+        if (empty($this->page->cm->context)) {
+            if ($this->context->instanceid === $this->page->cm->id) {
+                $this->page->cm->context = $this->context;
+            } else {
+                $this->page->cm->context = get_context_instance(CONTEXT_MODULE, $this->page->cm->instance);
+            }
+        }
+
         $module = $DB->get_record('modules', array('id'=>$this->page->cm->module));
         if (!$module) {
             debugging('Invalid Module ID picked up while attempting to load the activity for the navigation', DEBUG_DEVELOPER);