Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-37206 preload course format renderer in course/view.php

Also fixed bug with hardcoded default 'weeks' format
  • Loading branch information...
commit 8afb1cc8f81cf1d485576fce821ac993d1c9e2ae 1 parent ca48fe5
@marinaglancy marinaglancy authored
Showing with 14 additions and 4 deletions.
  1. +14 −4 course/view.php
View
18 course/view.php
@@ -117,15 +117,25 @@
}
add_to_log($course->id, 'course', $loglabel, "view.php?". $logparam, $infoid);
- $course->format = clean_param($course->format, PARAM_ALPHA);
- if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) {
- $course->format = 'weeks'; // Default format is weeks
- }
+ // Fix course format if it is no longer installed
+ $course->format = course_get_format($course)->get_format();
$PAGE->set_pagelayout('course');
$PAGE->set_pagetype('course-view-' . $course->format);
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
+ // Preload course format renderer before output starts.
+ // This is a little hacky but necessary since
+ // format.php is not included until after output starts
+ if (file_exists($CFG->dirroot.'/course/format/'.$course->format.'/renderer.php')) {
+ require_once($CFG->dirroot.'/course/format/'.$course->format.'/renderer.php');
+ if (class_exists('format_'.$course->format.'_renderer')) {
+ // call get_renderer only if renderer is defined in format plugin
+ // otherwise an exception would be thrown
+ $PAGE->get_renderer('format_'. $course->format);
+ }
+ }
+
if ($reset_user_allowed_editing) {
// ugly hack
unset($PAGE->_user_allowed_editing);
Please sign in to comment.
Something went wrong with that request. Please try again.