Skip to content

Commit 499ffa4

Browse files
committed
MDL-85391 course: Handle null course urls
Course urls may be null when navigation is set to true. The return value from course_get_url being null was not being handled before this change, which could lead to an exception causing the page not to load.
1 parent b479c7a commit 499ffa4

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

course/format/classes/output/local/content/sectionselector.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ public function export_for_template(\renderer_base $output): stdClass {
120120
nothing: ['' => get_string('jumpto')],
121121
);
122122
// Disable the current section.
123-
$select->set_option_disabled($disabledlink);
123+
if (!is_null($disabledlink)) {
124+
$select->set_option_disabled($disabledlink);
125+
}
124126
$select->class = 'jumpmenu';
125127
$select->formid = 'sectionmenu';
126128

@@ -143,17 +145,19 @@ private function add_section_menu(
143145
bool $indent = false
144146
) {
145147
$url = $this->get_section_url($course, $section);
146-
$indentation = $indent ? self::INDENTER : '';
147-
$this->sectionmenu[$url] = $indentation . $format->get_section_name($section);
148+
if (!is_null($url)) {
149+
$indentation = $indent ? self::INDENTER : '';
150+
$this->sectionmenu[$url] = $indentation . $format->get_section_name($section);
151+
}
148152
}
149153

150154
/**
151155
* Get the section url.
152156
* @param stdClass $course
153157
* @param section_info $section
154-
* @return string
158+
* @return string|null
155159
*/
156-
private function get_section_url(stdClass $course, section_info $section): string {
157-
return course_get_url($course, (object) $section, ['navigation' => true])->out(false);
160+
private function get_section_url(stdClass $course, section_info $section): ?string {
161+
return course_get_url($course, (object) $section, ['navigation' => true])?->out(false);
158162
}
159163
}

0 commit comments

Comments
 (0)