From 2a40043b1ca2425a55da880dce71851f82230744 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 12 Sep 2025 13:37:06 +0100 Subject: [PATCH] MDL-86627 cohort: format name correctly in report entity column. --- .../reportbuilder/local/entities/cohort.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cohort/classes/reportbuilder/local/entities/cohort.php b/cohort/classes/reportbuilder/local/entities/cohort.php index 4fca506d7ad..437a24df737 100644 --- a/cohort/classes/reportbuilder/local/entities/cohort.php +++ b/cohort/classes/reportbuilder/local/entities/cohort.php @@ -133,8 +133,20 @@ class cohort extends base { )) ->add_joins($this->get_joins()) ->set_type(column::TYPE_TEXT) - ->add_fields("{$tablealias}.name") - ->set_is_sortable(true); + ->add_join($this->get_context_join()) + ->add_field("{$tablealias}.name") + ->add_fields(context_helper::get_preload_record_columns_sql($contextalias)) + ->set_is_sortable(true) + ->set_callback(static function (?string $name, stdClass $cohort): string { + if ($name === null || $cohort->ctxid === null) { + return ''; + } + + context_helper::preload_from_record(clone $cohort); + $context = context::instance_by_id($cohort->ctxid); + + return format_string($name, options: ['context' => $context]); + }); // ID number column. $columns[] = (new column(