Skip to content

Commit

Permalink
Preview shortname if course custom field empty (#579)
Browse files Browse the repository at this point in the history
Previously if customcertelement_coursefield was a course custom field
and this field had no value then it did not appear on the reposition
page and so could not be dragged to the required location.  Now when
this field has no value its shortname is shown instead.
  • Loading branch information
leonstr authored and mdjnelson committed Dec 29, 2023
1 parent 25fece8 commit 0b13130
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion element/coursefield/classes/element.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ protected function get_course_field_value(\stdClass $course, bool $preview) : st
if (is_number($field)) { // Must be a custom course profile field.
$handler = \core_course\customfield\course_handler::create();
$data = $handler->get_instance_data($course->id, true);
if (!empty($data[$field])) {
if ($preview && empty($data[$field]->export_value())) {
$fields = $handler->get_fields();
$value = $fields[$field]->get('shortname');
} else if (!empty($data[$field])) {
$value = $data[$field]->export_value();
}

Expand Down

0 comments on commit 0b13130

Please sign in to comment.