From c3db3298ddeb2dc1cb3094f146d4514bc1a09539 Mon Sep 17 00:00:00 2001 From: Jackson D'souza Date: Tue, 15 Nov 2022 13:27:35 +0000 Subject: [PATCH 1/4] MDL-75571 calendar: Activity icon * Use Activity get_icon_url helper method to fetch icon. --- calendar/classes/external/event_icon_exporter.php | 4 ++++ calendar/templates/event_item.mustache | 3 ++- calendar/templates/upcoming_mini.mustache | 9 ++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/calendar/classes/external/event_icon_exporter.php b/calendar/classes/external/event_icon_exporter.php index 9f474075900..f6bdf4c12f0 100644 --- a/calendar/classes/external/event_icon_exporter.php +++ b/calendar/classes/external/event_icon_exporter.php @@ -61,11 +61,13 @@ class event_icon_exporter extends exporter { $iscourseevent = ($course && !empty($courseid) && $courseid != SITEID && empty($groupid)); $isgroupevent = ($group && !empty($groupid)); $isuserevent = ($user && !empty($userid)); + $iconurl = ''; if ($isactivityevent) { $key = 'monologo'; $component = $coursemodule->get('modname'); + $iconurl = get_fast_modinfo($courseid)->get_cm($coursemodule->get('id'))->get_icon_url()->out(false); if (get_string_manager()->string_exists($event->get_type(), $component)) { $alttext = get_string($event->get_type(), $component); } else { @@ -118,6 +120,7 @@ class event_icon_exporter extends exporter { $data->key = $key; $data->component = $component; $data->alttext = $alttext; + $data->iconurl = $iconurl; parent::__construct($data, $related); } @@ -132,6 +135,7 @@ class event_icon_exporter extends exporter { 'key' => ['type' => PARAM_TEXT], 'component' => ['type' => PARAM_TEXT], 'alttext' => ['type' => PARAM_TEXT], + 'iconurl' => ['type' => PARAM_TEXT], ]; } diff --git a/calendar/templates/event_item.mustache b/calendar/templates/event_item.mustache index f26580e8949..2ac7c811f4e 100644 --- a/calendar/templates/event_item.mustache +++ b/calendar/templates/event_item.mustache @@ -41,7 +41,8 @@ "icon": { "key": "i/courseevent", "component": "core", - "alttext": "Some course event" + "alttext": "Some course event", + "iconurl": "#" }, "editurl": "#", "url": "#" diff --git a/calendar/templates/upcoming_mini.mustache b/calendar/templates/upcoming_mini.mustache index 6838eae1d55..91a7e5e3d29 100644 --- a/calendar/templates/upcoming_mini.mustache +++ b/calendar/templates/upcoming_mini.mustache @@ -45,7 +45,14 @@ }} data-region="event-item"{{! }}>
- {{#icon}}{{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}}{{/icon}} + {{#icon}} + {{#iconurl}} + {{alttext}} + {{/iconurl}} + {{^iconurl}} + {{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}} + {{/iconurl}} + {{/icon}}
From fc67298a2764e54c7ee7ae1bb26c1699d0e9c0f8 Mon Sep 17 00:00:00 2001 From: Jackson D'souza Date: Mon, 28 Nov 2022 12:00:15 +0000 Subject: [PATCH 2/4] MDL-75571 block_timeline: Display custom activity icon if available. --- blocks/timeline/templates/event-list-item.mustache | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/blocks/timeline/templates/event-list-item.mustache b/blocks/timeline/templates/event-list-item.mustache index 46b3f8fc0f8..a28588cd102 100644 --- a/blocks/timeline/templates/event-list-item.mustache +++ b/blocks/timeline/templates/event-list-item.mustache @@ -40,7 +40,8 @@ "icon": { "key": "icon", "component": "mod_assign", - "alttext": "Assignment icon" + "alttext": "Assignment icon", + "iconurl": "#" }, "overdue": false, "purpose": "assessment" @@ -54,7 +55,14 @@ {{#userdate}} {{timesort}}, {{#str}} strftimetime24, core_langconfig {{/str}} {{/userdate}}
- {{#icon}}{{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}}{{/icon}} + {{#icon}} + {{#iconurl}} + {{alttext}} + {{/iconurl}} + {{^iconurl}} + {{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}} + {{/iconurl}} + {{/icon}}
From c48f443c327c9b928cbbd2f4c7a400773a5ae35e Mon Sep 17 00:00:00 2001 From: Jackson D'souza Date: Mon, 28 Nov 2022 12:01:17 +0000 Subject: [PATCH 3/4] MDL-75571 theme_boost: Activity icon * Use Activity get_icon_url helper method to fetch icon. --- theme/boost/classes/output/core_renderer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/theme/boost/classes/output/core_renderer.php b/theme/boost/classes/output/core_renderer.php index 8047d6df207..3d7ba9ecf28 100644 --- a/theme/boost/classes/output/core_renderer.php +++ b/theme/boost/classes/output/core_renderer.php @@ -161,7 +161,8 @@ class core_renderer extends \core_renderer { $heading = $this->page->course->fullname; } else { $heading = $this->page->cm->get_formatted_name(); - $imagedata = $this->pix_icon('monologo', '', $this->page->activityname, ['class' => 'activityicon']); + $imagedata = html_writer::img($this->page->cm->get_icon_url()->out(false), '', + ['class' => 'icon activityicon', 'aria-hidden' => 'true']); $purposeclass = plugin_supports('mod', $this->page->activityname, FEATURE_MOD_PURPOSE); $purposeclass .= ' activityiconcontainer'; $purposeclass .= ' modicon_' . $this->page->activityname; From de182b9a22bab3f4c988a858f75f81495f38bab7 Mon Sep 17 00:00:00 2001 From: Jackson D'souza Date: Mon, 28 Nov 2022 12:03:39 +0000 Subject: [PATCH 4/4] MDL-75571 tool_componentlibrary: Custom activity icon --- .../moodle/components/activityicons.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/admin/tool/componentlibrary/content/moodle/components/activityicons.md b/admin/tool/componentlibrary/content/moodle/components/activityicons.md index 2a3959aba92..9ed35978d1a 100644 --- a/admin/tool/componentlibrary/content/moodle/components/activityicons.md +++ b/admin/tool/componentlibrary/content/moodle/components/activityicons.md @@ -81,6 +81,30 @@ $activity-icon-colors: ( ); {{}} +### Custom activity icons + +Some activities allow icons to be customised. This can be done by implementing callback XXX_get_coursemodule_info() returning instance of object e.g. mod/lti/lib.php + +{{< php >}} +$info = new cached_cm_info(); +$info->iconurl = new moodle_url('https://moodle.org/theme/moodleorg/pix/moodle_logo_small.svg'); +{{< /php >}} + +To get this customised icon, use: + +{{< php >}} +$iconurl = get_fast_modinfo($courseid)->get_cm($cmid)->get_icon_url()->out(false); +{{< /php >}} + +
+
+ lti icon
+
+
external
+ +
+
+ ## Examples