1 |
efrain |
1 |
---
|
|
|
2 |
layout: docs
|
|
|
3 |
title: "Activity icons"
|
|
|
4 |
description: "Activity icons are used to quickly identify the activity types"
|
|
|
5 |
draft: false
|
|
|
6 |
weight: 5
|
|
|
7 |
toc: true
|
|
|
8 |
tags:
|
|
|
9 |
- Available
|
|
|
10 |
- '4.0'
|
|
|
11 |
- Updated
|
1441 |
ariadna |
12 |
- '5.0'
|
1 |
efrain |
13 |
---
|
|
|
14 |
|
|
|
15 |
## Activity icon types
|
|
|
16 |
|
|
|
17 |
Moodle activity icons are single black SVG icons that are stored in `mod/PLUGINNAME/pix/monologo.svg`.
|
|
|
18 |
|
1441 |
ariadna |
19 |
## Rendering activity icons
|
1 |
efrain |
20 |
|
1441 |
ariadna |
21 |
The `core_course\output\activity_icon` class is used to render activity icons. It can be used in several ways depending on the context. Also, there is the `core_course\activity_icon` template that can be included directly from mustache templates.
|
|
|
22 |
|
|
|
23 |
### Rendering the activity plugin icon
|
|
|
24 |
|
|
|
25 |
The following example shows how to render the default activity icon:
|
|
|
26 |
|
|
|
27 |
{{< php >}}
|
|
|
28 |
use core_course\output\activity_icon;
|
|
|
29 |
$renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer();
|
|
|
30 |
|
|
|
31 |
$icon = activity_icon::from_modname('quiz');
|
|
|
32 |
|
|
|
33 |
echo $renderer->render($icon);
|
|
|
34 |
{{< /php >}}
|
|
|
35 |
|
|
|
36 |
By default, the activity icon will be rendered colored with the activity purpose color (see below).
|
|
|
37 |
|
|
|
38 |
### Rendering the activity icon from a cm_info object
|
|
|
39 |
|
|
|
40 |
Specific activity instances can have their own custom icons. For example, the `mod_resource` displays the MIME type icon for the resource. To render the activity icon from a `cm_info` object, use the static constructor `from_cm_info`. The method will return an instance of `activity_icon` with the icon URL set to the custom icon if necessary.
|
|
|
41 |
|
|
|
42 |
It is possible to render the activity icon from a `cm_info` object:
|
|
|
43 |
|
|
|
44 |
{{< php >}}
|
|
|
45 |
use core_course\output\activity_icon;
|
|
|
46 |
$renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer();
|
|
|
47 |
$cminfo = get_fast_modinfo($courseid)->get_cm($cmid);
|
|
|
48 |
|
|
|
49 |
$icon = activity_icon::from_cm_info($cminfo);
|
|
|
50 |
|
|
|
51 |
echo $renderer->render($icon);
|
|
|
52 |
{{< /php >}}
|
|
|
53 |
|
|
|
54 |
### Rendering the activity icon in dark color
|
|
|
55 |
|
|
|
56 |
There are pages like the gradebook where the activity icons must be rendered in black color for accessibility or usability reasons. The `core_course\output\activity_icon` class has a `set_colourize` method to define if the icon must be colorized or not.
|
|
|
57 |
|
|
|
58 |
The following example shows how to render the default activity icon in black:
|
|
|
59 |
|
|
|
60 |
{{< php >}}
|
|
|
61 |
use core_course\output\activity_icon;
|
|
|
62 |
$renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer();
|
|
|
63 |
|
|
|
64 |
$icon = activity_icon::from_modname('quiz')
|
|
|
65 |
->set_colourize(false);
|
|
|
66 |
|
|
|
67 |
echo $renderer->render($icon);
|
|
|
68 |
{{< /php >}}
|
|
|
69 |
|
|
|
70 |
### Set the activity icon size
|
|
|
71 |
|
1 |
efrain |
72 |
When rendered in a page with limited space the icons will be shown in their original design, for example on the course gradebook where activity show in the grade table header.
|
|
|
73 |
|
1441 |
ariadna |
74 |
The `core_course\output\activity_icon` class has a `set_icon_size` method to define the icon size. The method accepts any value from `core\output\local\properties\iconsize` enum.
|
1 |
efrain |
75 |
|
1441 |
ariadna |
76 |
The following example shows how to render the default activity icon with a custom size:
|
1 |
efrain |
77 |
|
1441 |
ariadna |
78 |
{{< php >}}
|
|
|
79 |
use core_course\output\activity_icon;
|
|
|
80 |
use core\output\local\properties\iconsize;
|
|
|
81 |
$renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer();
|
1 |
efrain |
82 |
|
1441 |
ariadna |
83 |
$icon = activity_icon::from_modname('quiz')
|
|
|
84 |
->set_icon_size(iconsize::SIZE4);
|
1 |
efrain |
85 |
|
1441 |
ariadna |
86 |
echo $renderer->render($icon);
|
|
|
87 |
{{< /php >}}
|
1 |
efrain |
88 |
|
1441 |
ariadna |
89 |
### Add extra classes to the activity icon
|
1 |
efrain |
90 |
|
1441 |
ariadna |
91 |
The `core_course\output\activity_icon` class has a `set_extra_classes` method to add extra classes to the icon container.
|
1 |
efrain |
92 |
|
1441 |
ariadna |
93 |
The following example shows how to render the default activity icon with extra classes:
|
|
|
94 |
|
|
|
95 |
{{< php >}}
|
|
|
96 |
use core_course\output\activity_icon;
|
|
|
97 |
$renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer();
|
|
|
98 |
|
|
|
99 |
$icon = activity_icon::from_modname('quiz')
|
|
|
100 |
->set_extra_classes(['my-extra-class']);
|
|
|
101 |
|
|
|
102 |
echo $renderer->render($icon);
|
|
|
103 |
{{< /php >}}
|
|
|
104 |
|
|
|
105 |
## Activity purposes
|
|
|
106 |
|
1 |
efrain |
107 |
In the HTML for the example above you might notice the ```assessment``` css class after ```.activityiconcontainer```. This class is the result of assigning a *purpose* to the quiz activity in ```/mod/quiz/lib.php```.
|
|
|
108 |
|
|
|
109 |
{{< php >}}
|
|
|
110 |
function quiz_supports($feature) {
|
|
|
111 |
switch($feature) {
|
|
|
112 |
..
|
|
|
113 |
case FEATURE_PLAGIARISM: return true;
|
|
|
114 |
case FEATURE_MOD_PURPOSE: return MOD_PURPOSE_ASSESSMENT;
|
|
|
115 |
..
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
{{< /php >}}
|
|
|
119 |
|
|
|
120 |
Since Moodle 4.4, the available activity purposes are:
|
|
|
121 |
|
|
|
122 |
* Administration (MOD_PURPOSE_ADMINISTRATION)
|
|
|
123 |
* Assessment (MOD_PURPOSE_ASSESSMENT)
|
|
|
124 |
* Collaboration (MOD_PURPOSE_COLLABORATION)
|
|
|
125 |
* Communication (MOD_PURPOSE_COMMUNICATION)
|
|
|
126 |
* Interactive content (MOD_PURPOSE_INTERACTIVECONTENT)
|
|
|
127 |
* Resource (MOD_PURPOSE_CONTENT)
|
|
|
128 |
* Other (MOD_PURPOSE_OTHER)
|
|
|
129 |
|
|
|
130 |
> NOTE: On Moodle 4.3 downwards, MOD_PURPOSE_INTERFACE was also available, but it has been deprecated, so it's not recommended to use it.
|
|
|
131 |
|
|
|
132 |
### Purpose colours
|
|
|
133 |
|
1441 |
ariadna |
134 |
The activity icon colours can be customised using the theme Boost 'Raw initial SCSS' feature. The following variables are available:
|
1 |
efrain |
135 |
|
|
|
136 |
{{< highlight scss >}}
|
|
|
137 |
$activity-icon-administration-bg: #da58ef !default;
|
|
|
138 |
$activity-icon-assessment-bg: #f90086 !default;
|
|
|
139 |
$activity-icon-collaboration-bg: #5b40ff !default;
|
|
|
140 |
$activity-icon-communication-bg: #eb6200 !default;
|
|
|
141 |
$activity-icon-content-bg: #0099ad !default;
|
|
|
142 |
$activity-icon-interactivecontent-bg: #8d3d1b !default;
|
|
|
143 |
{{</ highlight >}}
|
|
|
144 |
|
|
|
145 |
### Custom activity icons
|
|
|
146 |
|
|
|
147 |
Some activities allow icons to be customised. This can be done by implementing callback `XXX_get_coursemodule_info()` returning instance of object (for instance, `mod/lti/lib.php`).
|
|
|
148 |
|
|
|
149 |
{{< php >}}
|
|
|
150 |
$info = new cached_cm_info();
|
|
|
151 |
$info->iconurl = new moodle_url('https://moodle.org/theme/moodleorg/pix/moodle_logo_small.svg');
|
|
|
152 |
{{< /php >}}
|
|
|
153 |
|
1441 |
ariadna |
154 |
To get this customised icon url, use:
|
1 |
efrain |
155 |
|
|
|
156 |
{{< php >}}
|
|
|
157 |
$iconurl = get_fast_modinfo($courseid)->get_cm($cmid)->get_icon_url()->out(false);
|
|
|
158 |
{{< /php >}}
|
|
|
159 |
|
1441 |
ariadna |
160 |
And to render the custom icon:
|
|
|
161 |
|
|
|
162 |
{{< php >}}
|
|
|
163 |
use core_course\output\activity_icon;
|
|
|
164 |
|
|
|
165 |
echo $OUTPUT->render(activity_icon::from_cm_info($cminfo));
|
|
|
166 |
{{< /php >}}
|
|
|
167 |
|
|
|
168 |
<div class="d-flex mb-3">
|
|
|
169 |
<div class="flex-shrink-0 activityiconcontainer lti me-3">
|
1 |
efrain |
170 |
<img alt="lti icon" title="lti icon" src="https://moodle.org/theme/moodleorg/pix/moodle_logo_small.svg" class="activityicon "> </div>
|
1441 |
ariadna |
171 |
<div class="flex-grow-1 align-self-center">
|
1 |
efrain |
172 |
<div class="text-uppercase small">external</div>
|
|
|
173 |
<div class="activityname"><a href="#">External tool module</a></div>
|
|
|
174 |
</div>
|
|
|
175 |
</div>
|
|
|
176 |
|
|
|
177 |
### Branded icons
|
|
|
178 |
|
|
|
179 |
Since Moodle 4.4, a new callback has been added to the modules. Branded icons are displayed with their original colours and they are not affected by the activity purpose colours.
|
|
|
180 |
|
|
|
181 |
{{< php >}}
|
|
|
182 |
/**
|
|
|
183 |
* Whether the activity is branded.
|
|
|
184 |
* This information is used, for instance, to decide if a filter should be applied to the icon or not.
|
|
|
185 |
*
|
|
|
186 |
* @return bool True if the activity is branded, false otherwise.
|
|
|
187 |
*/
|
|
|
188 |
function h5pactivity_is_branded(): bool {
|
|
|
189 |
return true;
|
|
|
190 |
}
|
|
|
191 |
{{< /php >}}
|
|
|
192 |
|
1441 |
ariadna |
193 |
<div class="d-flex mb-3">
|
|
|
194 |
<div class="flex-shrink-0 activityiconcontainer me-3">
|
1 |
efrain |
195 |
{{< image "h5pactivity/monologo.svg" "H5P activity icon" "activityicon">}} </div>
|
1441 |
ariadna |
196 |
<div class="flex-grow-1 align-self-center">
|
1 |
efrain |
197 |
<div class="text-uppercase small">h5pactivity</div>
|
|
|
198 |
<div class="activityname"><a href="#">H5P module</a></div>
|
|
|
199 |
</div>
|
|
|
200 |
</div>
|
|
|
201 |
|
|
|
202 |
## Examples
|
|
|
203 |
|
1441 |
ariadna |
204 |
<div class="d-flex mb-3">
|
|
|
205 |
<div class="flex-shrink-0 activityiconcontainer administration me-3">
|
1 |
efrain |
206 |
{{< image "quiz/monologo.svg" "Admin icon" "activityicon">}} </div>
|
1441 |
ariadna |
207 |
<div class="flex-grow-1 align-self-center">
|
1 |
efrain |
208 |
<div class="text-uppercase small">Administration</div>
|
|
|
209 |
<div class="activityname"><a href="#">Module name</a></div>
|
|
|
210 |
</div>
|
|
|
211 |
</div>
|
|
|
212 |
|
1441 |
ariadna |
213 |
<div class="d-flex mb-3">
|
|
|
214 |
<div class="flex-shrink-0 activityiconcontainer assessment me-3">
|
1 |
efrain |
215 |
{{< image "quiz/monologo.svg" "Assessment icon" "activityicon">}} </div>
|
1441 |
ariadna |
216 |
<div class="flex-grow-1 align-self-center">
|
1 |
efrain |
217 |
<div class="text-uppercase small">Assessment</div>
|
|
|
218 |
<div class="activityname"><a href="#">Module name</a></div>
|
|
|
219 |
</div>
|
|
|
220 |
</div>
|
|
|
221 |
|
1441 |
ariadna |
222 |
<div class="d-flex mb-3">
|
|
|
223 |
<div class="flex-shrink-0 activityiconcontainer collaboration me-3">
|
1 |
efrain |
224 |
{{< image "wiki/monologo.svg" "Collaboration icon" "activityicon">}} </div>
|
1441 |
ariadna |
225 |
<div class="flex-grow-1 align-self-center">
|
1 |
efrain |
226 |
<div class="text-uppercase small">Collaboration</div>
|
|
|
227 |
<div class="activityname"><a href="#">Module name</a></div>
|
|
|
228 |
</div>
|
|
|
229 |
</div>
|
|
|
230 |
|
1441 |
ariadna |
231 |
<div class="d-flex mb-3">
|
|
|
232 |
<div class="flex-shrink-0 activityiconcontainer communication me-3">
|
1 |
efrain |
233 |
{{< image "choice/monologo.svg" "Communication icon" "activityicon">}} </div>
|
1441 |
ariadna |
234 |
<div class="flex-grow-1 align-self-center">
|
1 |
efrain |
235 |
<div class="text-uppercase small">Communication</div>
|
|
|
236 |
<div class="activityname"><a href="#">Module name</a></div>
|
|
|
237 |
</div>
|
|
|
238 |
</div>
|
|
|
239 |
|
1441 |
ariadna |
240 |
<div class="d-flex mb-3">
|
|
|
241 |
<div class="flex-shrink-0 activityiconcontainer interactivecontent me-3">
|
1 |
efrain |
242 |
{{< image "lesson/monologo.svg" "Interactive content icon" "activityicon">}} </div>
|
1441 |
ariadna |
243 |
<div class="flex-grow-1 align-self-center">
|
1 |
efrain |
244 |
<div class="text-uppercase small">Interactive content</div>
|
|
|
245 |
<div class="activityname"><a href="#">Module name</a></div>
|
|
|
246 |
</div>
|
|
|
247 |
</div>
|
|
|
248 |
|
1441 |
ariadna |
249 |
<div class="d-flex mb-3">
|
|
|
250 |
<div class="flex-shrink-0 activityiconcontainer content me-3">
|
1 |
efrain |
251 |
{{< image "book/monologo.svg" "Resource icon" "activityicon">}} </div>
|
1441 |
ariadna |
252 |
<div class="flex-grow-1 align-self-center">
|
1 |
efrain |
253 |
<div class="text-uppercase small">Resource</div>
|
|
|
254 |
<div class="activityname"><a href="#">Module name</a></div>
|
|
|
255 |
</div>
|
|
|
256 |
</div>
|
|
|
257 |
|
1441 |
ariadna |
258 |
<div class="d-flex mb-3">
|
|
|
259 |
<div class="flex-shrink-0 activityiconcontainer me-3">
|
1 |
efrain |
260 |
{{< image "lti/monologo.svg" "Other icon" "activityicon">}} </div>
|
1441 |
ariadna |
261 |
<div class="flex-grow-1 align-self-center">
|
1 |
efrain |
262 |
<div class="text-uppercase small">Other</div>
|
|
|
263 |
<div class="activityname"><a href="#">Module name</a></div>
|
|
|
264 |
</div>
|
|
|
265 |
</div>
|