diff --git a/blocks/timeline/templates/event-list-item.mustache b/blocks/timeline/templates/event-list-item.mustache index efd5d1ab45a..e512ec35254 100644 --- a/blocks/timeline/templates/event-list-item.mustache +++ b/blocks/timeline/templates/event-list-item.mustache @@ -54,7 +54,10 @@ {{#userdate}} {{timesort}}, {{#str}} strftimetime24, core_langconfig {{/str}} {{/userdate}} -
+
{{#icon}} {{#iconurl}} {{alttext}} diff --git a/calendar/classes/external/event_icon_exporter.php b/calendar/classes/external/event_icon_exporter.php index bdc8b6386d3..715b10a6ff5 100644 --- a/calendar/classes/external/event_icon_exporter.php +++ b/calendar/classes/external/event_icon_exporter.php @@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die(); use \core\external\exporter; use \core_calendar\local\event\entities\event_interface; +use core_course\output\activity_icon; /** * Class for displaying a calendar event's icon. @@ -63,19 +64,25 @@ class event_icon_exporter extends exporter { $isuserevent = ($user && !empty($userid)); $iconurl = ''; $iconclass = ''; + $purpose = ''; if ($isactivityevent) { $key = 'monologo'; $component = $coursemodule->get('modname'); - $iconurl = get_fast_modinfo($courseid)->get_cm($coursemodule->get('id'))->get_icon_url(); - $iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter'; - $iconurl = $iconurl->out(false); if (get_string_manager()->string_exists($event->get_type(), $component)) { $alttext = get_string($event->get_type(), $component); } else { $alttext = get_string('activityevent', 'calendar'); } + + $renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer(); + $activityicon = activity_icon::from_cm_info($coursemodule->get_proxied_instance()) + ->set_title($alttext); + + $iconurl = $activityicon->get_icon_url($renderer)->out(false); + $iconclass = $activityicon->get_icon_classes($renderer); + $purpose = $activityicon->get_purpose(); } else if ($event->get_component()) { // Guess the icon and the title for the component event. By default display calendar icon and the // plugin name as the alttext. @@ -125,6 +132,7 @@ class event_icon_exporter extends exporter { $data->alttext = $alttext; $data->iconurl = $iconurl; $data->iconclass = $iconclass; + $data->purpose = $purpose; parent::__construct($data, $related); } @@ -141,6 +149,7 @@ class event_icon_exporter extends exporter { 'alttext' => ['type' => PARAM_TEXT], 'iconurl' => ['type' => PARAM_TEXT], 'iconclass' => ['type' => PARAM_TEXT], + 'purpose' => ['type' => PARAM_TEXT], ]; } diff --git a/calendar/templates/upcoming_mini.mustache b/calendar/templates/upcoming_mini.mustache index caed6a09801..93efd1eb554 100644 --- a/calendar/templates/upcoming_mini.mustache +++ b/calendar/templates/upcoming_mini.mustache @@ -44,7 +44,10 @@ }} data-eventtype-{{normalisedeventtype}}="1"{{! }} data-region="event-item"{{! }}> -
+
{{#icon}} {{#iconurl}} {{alttext}} diff --git a/course/classes/output/activity_icon.php b/course/classes/output/activity_icon.php index 6c0690b4de0..d495d7047b0 100644 --- a/course/classes/output/activity_icon.php +++ b/course/classes/output/activity_icon.php @@ -135,15 +135,9 @@ class activity_icon implements renderable, templatable { #[\Override] public function export_for_template(renderer_base $output): array { - if (!isset($this->iconurl)) { - $this->iconurl = $this->get_icon_url($output); - } - $needfiltering = $this->colourize && $this->iconurl->get_param('filtericon'); - $iconclass = $needfiltering ? '' : 'nofilter'; - $data = [ - 'icon' => $this->iconurl, - 'iconclass' => $iconclass, + 'icon' => $this->get_icon_url($output), + 'iconclass' => $this->get_icon_classes($output), 'modname' => $this->modname, 'pluginname' => get_string('pluginname', 'mod_' . $this->modname), 'purpose' => $this->purpose, @@ -165,6 +159,9 @@ class activity_icon implements renderable, templatable { * @return url */ public function get_icon_url(renderer_base $output): url { + if (isset($this->iconurl)) { + return $this->iconurl; + } $icon = $output->image_url('monologo', $this->modname); // Legacy activity modules may only have an `icon` icon instead of a `monologo` icon. $ismonologo = component::has_monologo_icon('mod', $this->modname); @@ -174,6 +171,7 @@ class activity_icon implements renderable, templatable { // The name of the param is not colorize to preserve backward compatibility. $icon->param('filtericon', 1); } + $this->iconurl = $icon; return $icon; } @@ -213,6 +211,20 @@ class activity_icon implements renderable, templatable { return $this->extraclasses; } + /** + * Get the icon classes. + * + * @param renderer_base $output + * @return string + */ + public function get_icon_classes(renderer_base $output): string { + $result = 'activityicon icon'; + $iconurl = $this->get_icon_url($output); + $needfiltering = $this->colourize && $iconurl->get_param('filtericon'); + $result .= ($needfiltering) ? '' : ' nofilter'; + return $result; + } + /** * Get the icon size. * diff --git a/course/templates/activity_icon.mustache b/course/templates/activity_icon.mustache index 5929a09de7a..382b84d8f3a 100644 --- a/course/templates/activity_icon.mustache +++ b/course/templates/activity_icon.mustache @@ -36,7 +36,7 @@ >