Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 7... Línea 7...
7
toc: true
7
toc: true
8
tags:
8
tags:
9
- Available
9
- Available
10
- '4.0'
10
- '4.0'
11
- Updated
11
- Updated
12
- '4.4'
12
- '5.0'
13
---
13
---
Línea 14... Línea 14...
14
 
14
 
Línea 15... Línea 15...
15
## Activity icon types
15
## Activity icon types
Línea -... Línea 16...
-
 
16
 
-
 
17
Moodle activity icons are single black SVG icons that are stored in `mod/PLUGINNAME/pix/monologo.svg`.
-
 
18
 
-
 
19
## Rendering activity icons
-
 
20
 
-
 
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).
16
 
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);
Línea 17... Línea 68...
17
Moodle activity icons are single black SVG icons that are stored in `mod/PLUGINNAME/pix/monologo.svg`.
68
{{< /php >}}
Línea 18... Línea 69...
18
 
69
 
Línea 19... Línea -...
19
### Minimal activity icons
-
 
20
 
-
 
21
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.
-
 
22
 
70
### Set the activity icon size
23
> NOTE: The icon is using the ```.icon``` CSS class which limits the maximum width and height. It's recommended to define width and height into the SVG.
-
 
24
 
-
 
25
{{< example >}}
-
 
Línea -... Línea 71...
-
 
71
 
26
<div class="d-flex mb-3">
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
 
-
 
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.
Línea 27... Línea 75...
27
    <div class="d-flex border align-items-center p-1">
75
 
-
 
76
The following example shows how to render the default activity icon with a custom size:
Línea 28... Línea -...
28
        {{< image "quiz/monologo.svg" "Quiz icon" "icon">}} Multiple choice quiz 1
-
 
-
 
77
 
-
 
78
{{< php >}}
Línea 29... Línea 79...
29
    </div>
79
use core_course\output\activity_icon;
-
 
80
use core\output\local\properties\iconsize;
30
</div>
81
$renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer();
-
 
82
 
31
{{< /example  >}}
83
$icon = activity_icon::from_modname('quiz')
32
 
-
 
33
### Coloured activity icons
-
 
34
 
-
 
35
In places like the course page and the activity chooser icons have a more prominent role and they should be rendered outlined colored against a transparent background.
-
 
36
 
-
 
Línea -... Línea 84...
-
 
84
    ->set_icon_size(iconsize::SIZE4);
-
 
85
 
-
 
86
echo $renderer->render($icon);
-
 
87
{{< /php >}}
-
 
88
 
-
 
89
### Add extra classes to the activity icon
-
 
90
 
-
 
91
The `core_course\output\activity_icon` class has a `set_extra_classes` method to add extra classes to the icon container.
-
 
92
 
-
 
93
The following example shows how to render the default activity icon with extra classes:
37
The CSS classes for these icons are ```activityiconcontainer``` wrapper class with the added activity name. And the ```activityicon``` class for the image. See the template ```course/format/templates/local/content/cm/title.mustache``` for more info.
94
 
Línea 38... Línea 95...
38
 
95
{{< php >}}
Línea 39... Línea 96...
39
<div class="media mb-3">
96
use core_course\output\activity_icon;
40
    <div class="activityiconcontainer assessment mr-3">
97
$renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer();
Línea 72... Línea 129...
72
 
129
 
Línea 73... Línea 130...
73
> 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.
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.
Línea 74... Línea 131...
74
 
131
 
Línea 75... Línea 132...
75
### Purpose colours
132
### Purpose colours
76
 
133
 
77
The activity icon colours can be customised using the theme Boost 'Raw initial SCSS' feature. Simply copy any of these scss variables that you want to customize, change the colour value, generate the filter using, for instance https://codepen.io/sosuke/pen/Pjoqqp and done! There is no background colour or filter for the 'Other' or the 'Interface' purposes.
134
The activity icon colours can be customised using the theme Boost 'Raw initial SCSS' feature. The following variables are available:
78
 
135
 
79
{{< highlight scss >}}
136
{{< highlight scss >}}
80
$activity-icon-administration-bg:     #da58ef !default;
137
$activity-icon-administration-bg:     #da58ef !default;
81
$activity-icon-assessment-bg:         #f90086 !default;
138
$activity-icon-assessment-bg:         #f90086 !default;
82
$activity-icon-collaboration-bg:      #5b40ff !default;
-
 
83
$activity-icon-communication-bg:      #eb6200 !default;
-
 
84
$activity-icon-content-bg:            #0099ad !default;
-
 
85
$activity-icon-interactivecontent-bg: #8d3d1b !default;
-
 
86
 
-
 
87
$activity-icon-administration-filter:
-
 
88
    invert(45%) sepia(46%) saturate(3819%) hue-rotate(260deg) brightness(101%) contrast(87%) !default;
-
 
89
$activity-icon-assessment-filter:
-
 
90
    invert(36%) sepia(98%) saturate(6969%) hue-rotate(315deg) brightness(90%) contrast(119%) !default;
-
 
91
$activity-icon-collaboration-filter:
-
 
92
    invert(25%) sepia(54%) saturate(6226%) hue-rotate(245deg) brightness(100%) contrast(102%) !default;
-
 
93
$activity-icon-communication-filter:
-
 
94
    invert(48%) sepia(74%) saturate(4887%) hue-rotate(11deg) brightness(102%) contrast(101%) !default;
-
 
95
$activity-icon-content-filter:
139
$activity-icon-collaboration-bg:      #5b40ff !default;
Línea 96... Línea 140...
96
    invert(49%) sepia(52%) saturate(4675%) hue-rotate(156deg) brightness(89%) contrast(102%) !default;
140
$activity-icon-communication-bg:      #eb6200 !default;
Línea 97... Línea 141...
97
$activity-icon-interactivecontent-filter:
141
$activity-icon-content-bg:            #0099ad !default;
Línea 105... Línea 149...
105
{{< php >}}
149
{{< php >}}
106
$info = new cached_cm_info();
150
$info = new cached_cm_info();
107
$info->iconurl = new moodle_url('https://moodle.org/theme/moodleorg/pix/moodle_logo_small.svg');
151
$info->iconurl = new moodle_url('https://moodle.org/theme/moodleorg/pix/moodle_logo_small.svg');
108
{{< /php >}}
152
{{< /php >}}
Línea 109... Línea 153...
109
 
153
 
Línea 110... Línea 154...
110
To get this customised icon, use:
154
To get this customised icon url, use:
111
 
155
 
112
{{< php >}}
156
{{< php >}}
Línea -... Línea 157...
-
 
157
$iconurl = get_fast_modinfo($courseid)->get_cm($cmid)->get_icon_url()->out(false);
-
 
158
{{< /php >}}
-
 
159
 
-
 
160
And to render the custom icon:
-
 
161
 
-
 
162
{{< php >}}
-
 
163
use core_course\output\activity_icon;
-
 
164
 
113
$iconurl = get_fast_modinfo($courseid)->get_cm($cmid)->get_icon_url()->out(false);
165
echo $OUTPUT->render(activity_icon::from_cm_info($cminfo));
114
{{< /php >}}
166
{{< /php >}}
115
 
167
 
116
<div class="media mb-3">
168
<div class="d-flex mb-3">
117
    <div class="activityiconcontainer lti mr-3">
169
    <div class="flex-shrink-0 activityiconcontainer lti me-3">
118
        <img alt="lti icon" title="lti icon" src="https://moodle.org/theme/moodleorg/pix/moodle_logo_small.svg" class="activityicon ">    </div>
170
        <img alt="lti icon" title="lti icon" src="https://moodle.org/theme/moodleorg/pix/moodle_logo_small.svg" class="activityicon ">    </div>
119
    <div class="media-body align-self-center">
171
    <div class="flex-grow-1 align-self-center">
120
        <div class="text-uppercase small">external</div>
172
        <div class="text-uppercase small">external</div>
Línea 136... Línea 188...
136
function h5pactivity_is_branded(): bool {
188
function h5pactivity_is_branded(): bool {
137
    return true;
189
    return true;
138
}
190
}
139
{{< /php >}}
191
{{< /php >}}
Línea 140... Línea 192...
140
 
192
 
141
<div class="media mb-3">
193
<div class="d-flex mb-3">
142
    <div class="activityiconcontainer mr-3">
194
    <div class="flex-shrink-0 activityiconcontainer me-3">
143
        {{< image "h5pactivity/monologo.svg" "H5P activity icon" "activityicon">}}    </div>
195
        {{< image "h5pactivity/monologo.svg" "H5P activity icon" "activityicon">}}    </div>
144
    <div class="media-body align-self-center">
196
    <div class="flex-grow-1 align-self-center">
145
        <div class="text-uppercase small">h5pactivity</div>
197
        <div class="text-uppercase small">h5pactivity</div>
146
        <div class="activityname"><a href="#">H5P module</a></div>
198
        <div class="activityname"><a href="#">H5P module</a></div>
147
    </div>
199
    </div>
Línea 148... Línea 200...
148
</div>
200
</div>
Línea 149... Línea 201...
149
 
201
 
150
## Examples
202
## Examples
151
 
203
 
152
<div class="media mb-3">
204
<div class="d-flex mb-3">
153
    <div class="activityiconcontainer administration mr-3">
205
    <div class="flex-shrink-0 activityiconcontainer administration me-3">
154
        {{< image "quiz/monologo.svg" "Admin icon" "activityicon">}}    </div>
206
        {{< image "quiz/monologo.svg" "Admin icon" "activityicon">}}    </div>
155
    <div class="media-body align-self-center">
207
    <div class="flex-grow-1 align-self-center">
156
        <div class="text-uppercase small">Administration</div>
208
        <div class="text-uppercase small">Administration</div>
Línea 157... Línea 209...
157
        <div class="activityname"><a href="#">Module name</a></div>
209
        <div class="activityname"><a href="#">Module name</a></div>
158
    </div>
210
    </div>
159
</div>
211
</div>
160
 
212
 
161
<div class="media mb-3">
213
<div class="d-flex mb-3">
162
    <div class="activityiconcontainer assessment mr-3">
214
    <div class="flex-shrink-0 activityiconcontainer assessment me-3">
163
        {{< image "quiz/monologo.svg" "Assessment icon" "activityicon">}}    </div>
215
        {{< image "quiz/monologo.svg" "Assessment icon" "activityicon">}}    </div>
164
    <div class="media-body align-self-center">
216
    <div class="flex-grow-1 align-self-center">
Línea 165... Línea 217...
165
        <div class="text-uppercase small">Assessment</div>
217
        <div class="text-uppercase small">Assessment</div>
166
        <div class="activityname"><a href="#">Module name</a></div>
218
        <div class="activityname"><a href="#">Module name</a></div>
167
    </div>
219
    </div>
168
</div>
220
</div>
169
 
221
 
170
<div class="media mb-3">
222
<div class="d-flex mb-3">
171
    <div class="activityiconcontainer collaboration mr-3">
223
    <div class="flex-shrink-0 activityiconcontainer collaboration me-3">
172
        {{< image "wiki/monologo.svg" "Collaboration icon" "activityicon">}}    </div>
224
        {{< image "wiki/monologo.svg" "Collaboration icon" "activityicon">}}    </div>
Línea 173... Línea 225...
173
    <div class="media-body align-self-center">
225
    <div class="flex-grow-1 align-self-center">
174
        <div class="text-uppercase small">Collaboration</div>
226
        <div class="text-uppercase small">Collaboration</div>
175
        <div class="activityname"><a href="#">Module name</a></div>
227
        <div class="activityname"><a href="#">Module name</a></div>
176
    </div>
228
    </div>
177
</div>
229
</div>
178
 
230
 
179
<div class="media mb-3">
231
<div class="d-flex mb-3">
180
    <div class="activityiconcontainer communication mr-3">
232
    <div class="flex-shrink-0 activityiconcontainer communication me-3">
Línea 181... Línea 233...
181
        {{< image "choice/monologo.svg" "Communication icon" "activityicon">}}    </div>
233
        {{< image "choice/monologo.svg" "Communication icon" "activityicon">}}    </div>
182
    <div class="media-body align-self-center">
234
    <div class="flex-grow-1 align-self-center">
183
        <div class="text-uppercase small">Communication</div>
235
        <div class="text-uppercase small">Communication</div>
184
        <div class="activityname"><a href="#">Module name</a></div>
236
        <div class="activityname"><a href="#">Module name</a></div>
185
    </div>
237
    </div>
186
</div>
238
</div>
187
 
239
 
188
<div class="media mb-3">
240
<div class="d-flex mb-3">
Línea 189... Línea 241...
189
    <div class="activityiconcontainer interactivecontent mr-3">
241
    <div class="flex-shrink-0 activityiconcontainer interactivecontent me-3">
190
        {{< image "lesson/monologo.svg" "Interactive content icon" "activityicon">}}    </div>
242
        {{< image "lesson/monologo.svg" "Interactive content icon" "activityicon">}}    </div>
191
    <div class="media-body align-self-center">
243
    <div class="flex-grow-1 align-self-center">
192
        <div class="text-uppercase small">Interactive content</div>
244
        <div class="text-uppercase small">Interactive content</div>
193
        <div class="activityname"><a href="#">Module name</a></div>
245
        <div class="activityname"><a href="#">Module name</a></div>
194
    </div>
246
    </div>
195
</div>
247
</div>
196
 
248
 
Línea 197... Línea 249...
197
<div class="media mb-3">
249
<div class="d-flex mb-3">
198
    <div class="activityiconcontainer content mr-3">
250
    <div class="flex-shrink-0 activityiconcontainer content me-3">
199
        {{< image "book/monologo.svg" "Resource icon" "activityicon">}}    </div>
251
        {{< image "book/monologo.svg" "Resource icon" "activityicon">}}    </div>
200
    <div class="media-body align-self-center">
252
    <div class="flex-grow-1 align-self-center">
201
        <div class="text-uppercase small">Resource</div>
253
        <div class="text-uppercase small">Resource</div>
202
        <div class="activityname"><a href="#">Module name</a></div>
254
        <div class="activityname"><a href="#">Module name</a></div>
203
    </div>
255
    </div>
204
</div>
256
</div>