Skip to content

Commit

Permalink
Issue #592: Handle missing gradeitems as gracefully as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Peterburnett committed Jan 8, 2024
1 parent 9bb48de commit 20964d3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions element/gradeitemname/classes/element.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ protected function get_grade_item_name() : string {
$gradeitemid = substr($gradeitem, 10);
$gradeitem = \grade_item::fetch(['id' => $gradeitemid]);

return $gradeitem->get_name();
// If the gradeitem was not found, return an empty string.
// This will effectively prevent the element from rendering.
return $gradeitem ? $gradeitem->get_name() : '';
} else {
if (!$cm = $DB->get_record('course_modules', array('id' => $gradeitem))) {
return '';
Expand All @@ -141,7 +143,9 @@ protected function get_grade_item_name() : string {

$gradeitem = \grade_item::fetch($params);

return $gradeitem->get_name();
// If the gradeitem was not found, return an empty string.
// This will effectively prevent the element from rendering.
return $gradeitem ? $gradeitem->get_name() : '';
}
}
}

0 comments on commit 20964d3

Please sign in to comment.