diff --git a/element/gradeitemname/classes/element.php b/element/gradeitemname/classes/element.php index 2fcf40bc..b529ca8d 100644 --- a/element/gradeitemname/classes/element.php +++ b/element/gradeitemname/classes/element.php @@ -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 ''; @@ -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() : ''; } } }