From 4dd5bce866bfa6018f9bd2501db565135b6e65ca Mon Sep 17 00:00:00 2001 From: samhemelryk Date: Thu, 15 Oct 2009 06:37:45 +0000 Subject: [PATCH] navigation MDL-20568 Fixed notices and warning generated by navigation when page context is for a module but page cm has not been set. Also tacked on a tiny edit to fix missing alt tags --- lib/navigationlib.php | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index f29e2b0d66..868ad57c3f 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -405,7 +405,6 @@ class navigation_node { if ($this->icon!==null) { $icon = new html_image(); $icon->src = $this->icon; - $icon->alt = ''; $content = $OUTPUT->image($icon).' '.$content; } else if ($this->helpbutton!==null) { $content = sprintf('%s%s',trim($this->helpbutton),$content); @@ -1201,9 +1200,21 @@ class global_navigation extends navigation_node { protected function load_activity($keys) { 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; + if ($cm) { + $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); + return; + } + } + $module = $DB->get_record('modules', array('id'=>$PAGE->cm->module)); + if (!$module) { - echo "Invalid Module ID"; + debugging('Invalid Module ID picked up while attempting to load the activity for the navigation', DEBUG_DEVELOPER); return; } @@ -2824,9 +2835,26 @@ class settings_navigation extends navigation_node { */ protected function load_module_settings() { global $CFG, $DB; - $cm = $this->page->cm; - $module = $DB->get_record('modules', array('id'=>$cm->module)); + + if (!$this->page->cm && $this->context->contextlevel == CONTEXT_MODULE && $this->context->instanceid) { + $cm = get_coursemodule_from_id('chat', $this->context->instanceid); + $cm->context = $this->context; + if ($cm) { + $this->page->set_cm($cm, $this->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); + return; + } + } + + if (!$this->page->cm) { + debugging('The module has not been set against the page but we are attempting to generate module specific information for navigation', DEBUG_DEVELOPER); + return; + } + + $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); return; } -- 2.39.5