Skip to content

Commit 598c177

Browse files
committed
Move set_url() to format constructor
1 parent 1170d15 commit 598c177

2 files changed

Lines changed: 11 additions & 25 deletions

File tree

classes/output/renderer.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,6 @@
4747
*/
4848
class renderer extends section_renderer {
4949

50-
/**
51-
* Constructor method, calls the parent constructor.
52-
*
53-
* @param moodle_page $page
54-
* @param string $target one of rendering target constants
55-
*/
56-
public function __construct(\moodle_page $page, string $target) {
57-
parent::__construct($page, $target);
58-
59-
// REMOVED: Marker stuff.
60-
61-
// ADDED.
62-
// If we're on the view page, patch the URL to use the section ID instead of section number.
63-
if ($this->page->has_set_url()
64-
&& ($url = $this->page->url)->compare(new \moodle_url('/course/view.php'), URL_MATCH_BASE)
65-
&& $url->get_param('section')
66-
&& ($sectionid = optional_param('sectionid', null, PARAM_INT))) {
67-
$url->remove_params(['section']);
68-
$this->page->set_url($url, ['sectionid' => $sectionid]);
69-
}
70-
// END ADDED.
71-
72-
}
73-
7450
/**
7551
* Renders the provided widget and returns the HTML to display it.
7652
*

lib.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,21 @@ class format_multitopic extends core_courseformat\base {
9696
* @return format_multitopic
9797
*/
9898
protected function __construct($format, $courseid) {
99-
global $DB;
99+
global $DB, $PAGE;
100100
parent::__construct($format, $courseid);
101+
101102
if ($courseid) {
102103
$this->fmtrootsectionid = $DB->get_field('course_sections', 'id', ['section' => 0, 'course' => $courseid]);
103104
// TODO: Check if this is set correctly for new courses?
105+
106+
// If we're on the view page, patch the URL to use the section ID instead of section number.
107+
if ($PAGE->has_set_url()
108+
&& ($url = $PAGE->url)->compare(new \moodle_url('/course/view.php'), URL_MATCH_BASE)
109+
&& $url->get_param('section')
110+
&& ($sectionid = optional_param('sectionid', null, PARAM_INT))) {
111+
$url->remove_params(['section']);
112+
$PAGE->set_url($url, ['sectionid' => $sectionid]);
113+
}
104114
}
105115
}
106116
// END INCLUDED.

0 commit comments

Comments
 (0)