MDL-59336 themes: change FA mapping for i/new
[moodle.git] / lib / classes / output / icon_system_fontawesome.php
CommitLineData
95b06c13
DW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Contains class \core\output\icon_system
19 *
20 * @package core
21 * @category output
22 * @copyright 2016 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26namespace core\output;
27
e330b1c2
DW
28use renderer_base;
29use pix_icon;
30
b9b409cf
DW
31defined('MOODLE_INTERNAL') || die();
32
95b06c13
DW
33/**
34 * Class allowing different systems for mapping and rendering icons.
35 *
36 * Possible icon styles are:
37 * 1. standard - image tags are generated which point to pix icons stored in a plugin pix folder.
38 * 2. fontawesome - font awesome markup is generated with the name of the icon mapped from the moodle icon name.
39 * 3. inline - inline tags are used for svg and png so no separate page requests are made (at the expense of page size).
40 *
41 * @package core
42 * @category output
43 * @copyright 2016 Damyon Wiese
44 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45 */
46class icon_system_fontawesome extends icon_system_font {
47
b9b409cf
DW
48 /**
49 * @var array $map Cached map of moodle icon names to font awesome icon names.
50 */
51 private $map = [];
52
95b06c13
DW
53 public function get_core_icon_map() {
54 return [
55 'core:docs' => 'fa-info-circle',
ad056aa2
DW
56 'core:help' => 'fa-question-circle text-info',
57 'core:req' => 'fa-exclamation-circle text-danger',
95b06c13
DW
58 'core:a/add_file' => 'fa-file-o',
59 'core:a/create_folder' => 'fa-folder-o',
60 'core:a/download_all' => 'fa-download',
ad056aa2 61 'core:a/help' => 'fa-question-circle text-info',
95b06c13
DW
62 'core:a/logout' => 'fa-sign-out',
63 'core:a/refresh' => 'fa-refresh',
64 'core:a/search' => 'fa-search',
65 'core:a/setting' => 'fa-cog',
66 'core:a/view_icon_active' => 'fa-th',
67 'core:a/view_list_active' => 'fa-list',
68 'core:a/view_tree_active' => 'fa-folder',
69 'core:b/bookmark-new' => 'fa-bookmark',
70 'core:b/document-edit' => 'fa-pencil',
71 'core:b/document-new' => 'fa-file-o',
72 'core:b/document-properties' => 'fa-info',
73 'core:b/edit-copy' => 'fa-files-o',
74 'core:b/edit-delete' => 'fa-trash',
75 'core:e/abbr' => 'fa-comment',
76 'core:e/absolute' => 'fa-crosshairs',
77 'core:e/accessibility_checker' => 'fa-universal-access',
78 'core:e/acronym' => 'fa-comment',
79 'core:e/advance_hr' => 'fa-arrows-h',
80 'core:e/align_center' => 'fa-align-center',
81 'core:e/align_left' => 'fa-align-left',
82 'core:e/align_right' => 'fa-align-right',
83 'core:e/anchor' => 'fa-chain',
84 'core:e/backward' => 'fa-undo',
85 'core:e/bold' => 'fa-bold',
86 'core:e/bullet_list' => 'fa-list-ul',
87 'core:e/cell_props' => 'fa-info',
88 'core:e/cite' => 'fa-quote-right',
89 'core:e/cleanup_messy_code' => 'fa-eraser',
ad056aa2 90 'core:e/clear_formatting' => 'fa-i-cursor',
95b06c13
DW
91 'core:e/copy' => 'fa-clone',
92 'core:e/cut' => 'fa-scissors',
93 'core:e/decrease_indent' => 'fa-outdent',
94 'core:e/delete_col' => 'fa-minus',
95 'core:e/delete_row' => 'fa-minus',
96 'core:e/delete' => 'fa-minus',
97 'core:e/delete_table' => 'fa-minus',
98 'core:e/document_properties' => 'fa-info',
b9b409cf 99 'core:e/emoticons' => 'fa-smile-o',
95b06c13
DW
100 'core:e/find_replace' => 'fa-search-plus',
101 'core:e/forward' => 'fa-arrow-right',
102 'core:e/fullpage' => 'fa-arrows-alt',
103 'core:e/fullscreen' => 'fa-arrows-alt',
104 'core:e/help' => 'fa-question-circle',
105 'core:e/increase_indent' => 'fa-indent',
106 'core:e/insert_col_after' => 'fa-columns',
107 'core:e/insert_col_before' => 'fa-columns',
108 'core:e/insert_date' => 'fa-calendar',
109 'core:e/insert_edit_image' => 'fa-picture-o',
110 'core:e/insert_edit_link' => 'fa-link',
111 'core:e/insert_edit_video' => 'fa-video-camera',
112 'core:e/insert_file' => 'fa-file',
113 'core:e/insert_horizontal_ruler' => 'fa-arrows-h',
114 'core:e/insert_nonbreaking_space' => 'fa-square-o',
115 'core:e/insert_page_break' => 'fa-level-down',
116 'core:e/insert_row_after' => 'fa-plus',
117 'core:e/insert_row_before' => 'fa-plus',
118 'core:e/insert' => 'fa-plus',
119 'core:e/insert_time' => 'fa-clock-o',
120 'core:e/italic' => 'fa-italic',
121 'core:e/justify' => 'fa-align-justify',
122 'core:e/layers_over' => 'fa-level-up',
123 'core:e/layers' => 'fa-window-restore',
124 'core:e/layers_under' => 'fa-level-down',
125 'core:e/left_to_right' => 'fa-chevron-right',
126 'core:e/manage_files' => 'fa-files-o',
127 'core:e/math' => 'fa-calculator',
128 'core:e/merge_cells' => 'fa-compress',
129 'core:e/new_document' => 'fa-file-o',
130 'core:e/numbered_list' => 'fa-list-ol',
131 'core:e/page_break' => 'fa-level-down',
132 'core:e/paste' => 'fa-clipboard',
133 'core:e/paste_text' => 'fa-clipboard',
134 'core:e/paste_word' => 'fa-clipboard',
135 'core:e/prevent_autolink' => 'fa-exclamation',
136 'core:e/preview' => 'fa-search-plus',
137 'core:e/print' => 'fa-print',
138 'core:e/question' => 'fa-question',
139 'core:e/redo' => 'fa-repeat',
ad056aa2 140 'core:e/remove_link' => 'fa-chain-broken',
95b06c13
DW
141 'core:e/remove_page_break' => 'fa-remove',
142 'core:e/resize' => 'fa-expand',
143 'core:e/restore_draft' => 'fa-undo',
144 'core:e/restore_last_draft' => 'fa-undo',
145 'core:e/right_to_left' => 'fa-chevron-left',
146 'core:e/row_props' => 'fa-info',
147 'core:e/save' => 'fa-floppy-o',
148 'core:e/screenreader_helper' => 'fa-braille',
149 'core:e/search' => 'fa-search',
150 'core:e/select_all' => 'fa-arrows-h',
ad056aa2 151 'core:e/show_invisible_characters' => 'fa-eye-slash',
95b06c13 152 'core:e/source_code' => 'fa-code',
ad056aa2 153 'core:e/special_character' => 'fa-pencil-square-o',
95b06c13
DW
154 'core:e/spellcheck' => 'fa-check',
155 'core:e/split_cells' => 'fa-columns',
156 'core:e/strikethrough' => 'fa-strikethrough',
157 'core:e/styleprops' => 'fa-info',
158 'core:e/subscript' => 'fa-subscript',
159 'core:e/superscript' => 'fa-superscript',
160 'core:e/table_props' => 'fa-table',
161 'core:e/table' => 'fa-table',
162 'core:e/template' => 'fa-sticky-note',
163 'core:e/text_color_picker' => 'fa-paint-brush',
164 'core:e/text_color' => 'fa-paint-brush',
165 'core:e/text_highlight_picker' => 'fa-lightbulb-o',
166 'core:e/text_highlight' => 'fa-lightbulb-o',
167 'core:e/tick' => 'fa-check',
168 'core:e/toggle_blockquote' => 'fa-quote-left',
169 'core:e/underline' => 'fa-underline',
170 'core:e/undo' => 'fa-undo',
171 'core:e/visual_aid' => 'fa-universal-access',
172 'core:e/visual_blocks' => 'fa-audio-description',
95b06c13 173 'theme:fp/add_file' => 'fa-file-o',
85594276
MG
174 'theme:fp/alias' => 'fa-share',
175 'theme:fp/alias_sm' => 'fa-share',
95b06c13 176 'theme:fp/check' => 'fa-check',
3c885071 177 'theme:fp/create_folder' => 'fa-folder-o',
95b06c13
DW
178 'theme:fp/cross' => 'fa-remove',
179 'theme:fp/download_all' => 'fa-download',
180 'theme:fp/help' => 'fa-question-circle',
181 'theme:fp/link' => 'fa-link',
182 'theme:fp/link_sm' => 'fa-link',
183 'theme:fp/logout' => 'fa-sign-out',
184 'theme:fp/path_folder' => 'fa-folder',
185 'theme:fp/path_folder_rtl' => 'fa-folder',
186 'theme:fp/refresh' => 'fa-refresh',
187 'theme:fp/search' => 'fa-search',
188 'theme:fp/setting' => 'fa-cog',
189 'theme:fp/view_icon_active' => 'fa-th',
190 'theme:fp/view_list_active' => 'fa-list',
191 'theme:fp/view_tree_active' => 'fa-folder',
192 'core:i/assignroles' => 'fa-user-plus',
193 'core:i/backup' => 'fa-file-zip-o',
194 'core:i/badge' => 'fa-shield',
195 'core:i/calc' => 'fa-calculator',
196 'core:i/calendar' => 'fa-calendar',
ad056aa2 197 'core:i/caution' => 'fa-exclamation text-warning',
95b06c13
DW
198 'core:i/checked' => 'fa-check',
199 'core:i/checkpermissions' => 'fa-unlock-alt',
200 'core:i/cohort' => 'fa-users',
201 'core:i/competencies' => 'fa-check-square-o',
b9b409cf 202 'core:i/completion_self' => 'fa-user-o',
f3dacc38 203 'core:i/dashboard' => 'fa-tachometer',
95b06c13
DW
204 'core:i/lock' => 'fa-lock',
205 'core:i/courseevent' => 'fa-calendar',
95b06c13
DW
206 'core:i/db' => 'fa-database',
207 'core:i/delete' => 'fa-trash',
208 'core:i/down' => 'fa-arrow-down',
209 'core:i/dragdrop' => 'fa-arrows',
ad056aa2 210 'core:i/duration' => 'fa-clock-o',
95b06c13
DW
211 'core:i/edit' => 'fa-pencil',
212 'core:i/email' => 'fa-envelope',
b9b409cf 213 'core:i/enrolmentsuspended' => 'fa-pause',
95b06c13 214 'core:i/enrolusers' => 'fa-user-plus',
ad056aa2 215 'core:i/expired' => 'fa-exclamation text-warning',
b9b409cf 216 'core:i/export' => 'fa-download',
95b06c13
DW
217 'core:i/files' => 'fa-file',
218 'core:i/filter' => 'fa-filter',
219 'core:i/flagged' => 'fa-flag',
220 'core:i/folder' => 'fa-folder',
ad056aa2
DW
221 'core:i/grade_correct' => 'fa-check text-success',
222 'core:i/grade_incorrect' => 'fa-remove text-danger',
95b06c13 223 'core:i/grade_partiallycorrect' => 'fa-check-square',
0ac1dcd8 224 'core:i/grades' => 'fa-table',
95b06c13 225 'core:i/groupevent' => 'fa-group',
8857c715 226 'core:i/groupn' => 'fa-user',
95b06c13 227 'core:i/group' => 'fa-users',
8857c715
DW
228 'core:i/groups' => 'fa-user-circle',
229 'core:i/groupv' => 'fa-user-circle-o',
95b06c13 230 'core:i/hide' => 'fa-eye',
b9b409cf 231 'core:i/hierarchylock' => 'fa-lock',
95b06c13
DW
232 'core:i/import' => 'fa-level-up',
233 'core:i/info' => 'fa-info',
4413b466 234 'core:i/invalid' => 'fa-times text-danger',
95b06c13
DW
235 'core:i/item' => 'fa-circle',
236 'core:i/loading' => 'fa-circle-o-notch fa-spin',
237 'core:i/loading_small' => 'fa-circle-o-notch fa-spin',
238 'core:i/lock' => 'fa-lock',
239 'core:i/log' => 'fa-list-alt',
240 'core:i/mahara_host' => 'fa-id-badge',
241 'core:i/manual_item' => 'fa-square-o',
f7cfa26e
DM
242 'core:i/marked' => 'fa-circle',
243 'core:i/marker' => 'fa-circle-o',
95b06c13
DW
244 'core:i/mean' => 'fa-calculator',
245 'core:i/menu' => 'fa-ellipsis-v',
0cd6e1bf 246 'core:i/menubars' => 'fa-bars',
95b06c13
DW
247 'core:i/mnethost' => 'fa-external-link',
248 'core:i/moodle_host' => 'fa-graduation-cap',
249 'core:i/move_2d' => 'fa-arrows',
57ea73d0 250 'core:i/navigationitem' => 'fa-fw',
b9b409cf 251 'core:i/ne_red_mark' => 'fa-remove',
eca7e529 252 'core:i/new' => 'fa-bolt',
ad056aa2 253 'core:i/news' => 'fa-newspaper-o',
95b06c13
DW
254 'core:i/nosubcat' => 'fa-plus-square-o',
255 'core:i/notifications' => 'fa-bell',
256 'core:i/open' => 'fa-folder-open',
257 'core:i/outcomes' => 'fa-tasks',
258 'core:i/payment' => 'fa-money',
259 'core:i/permissionlock' => 'fa-lock',
260 'core:i/permissions' => 'fa-pencil-square-o',
261 'core:i/persona_sign_in_black' => 'fa-male',
262 'core:i/portfolio' => 'fa-id-badge',
263 'core:i/preview' => 'fa-search-plus',
264 'core:i/progressbar' => 'fa-spinner fa-spin',
265 'core:i/publish' => 'fa-share',
266 'core:i/questions' => 'fa-question',
267 'core:i/reload' => 'fa-refresh',
268 'core:i/report' => 'fa-area-chart',
269 'core:i/repository' => 'fa-hdd-o',
270 'core:i/restore' => 'fa-level-up',
271 'core:i/return' => 'fa-arrow-left',
ad056aa2
DW
272 'core:i/risk_config' => 'fa-exclamation text-muted',
273 'core:i/risk_managetrust' => 'fa-exclamation-triangle text-warning',
274 'core:i/risk_personal' => 'fa-exclamation-circle text-info',
275 'core:i/risk_spam' => 'fa-exclamation text-primary',
276 'core:i/risk_xss' => 'fa-exclamation-triangle text-danger',
95b06c13
DW
277 'core:i/role' => 'fa-user-md',
278 'core:i/rss' => 'fa-rss',
24a6b594 279 'core:i/rsssitelogo' => 'fa-graduation-cap',
95b06c13
DW
280 'core:i/scales' => 'fa-balance-scale',
281 'core:i/scheduled' => 'fa-calendar-check-o',
282 'core:i/search' => 'fa-search',
57ea73d0 283 'core:i/settings' => 'fa-cog',
95b06c13
DW
284 'core:i/show' => 'fa-eye-slash',
285 'core:i/siteevent' => 'fa-share-alt',
b9b409cf 286 'core:i/star-rating' => 'fa-star',
95b06c13
DW
287 'core:i/stats' => 'fa-line-chart',
288 'core:i/switch' => 'fa-exchange',
289 'core:i/switchrole' => 'fa-user-secret',
290 'core:i/twoway' => 'fa-arrows-h',
291 'core:i/unchecked' => 'fa-square-o',
292 'core:i/unflagged' => 'fa-flag-o',
293 'core:i/unlock' => 'fa-unlock',
294 'core:i/up' => 'fa-arrow-up',
295 'core:i/userevent' => 'fa-user',
296 'core:i/user' => 'fa-user',
297 'core:i/users' => 'fa-users',
4413b466 298 'core:i/valid' => 'fa-check text-success',
ad056aa2 299 'core:i/warning' => 'fa-exclamation text-warning',
95b06c13
DW
300 'core:i/withsubcat' => 'fa-plus-square',
301 'core:m/USD' => 'fa-usd',
302 'core:t/addcontact' => 'fa-address-card',
303 'core:t/add' => 'fa-plus',
304 'core:t/approve' => 'fa-thumbs-up',
305 'core:t/assignroles' => 'fa-user-circle',
306 'core:t/award' => 'fa-trophy',
307 'core:t/backpack' => 'fa-shopping-bag',
308 'core:t/backup' => 'fa-arrow-circle-down',
ad056aa2 309 'core:t/block' => 'fa-ban',
95b06c13
DW
310 'core:t/block_to_dock_rtl' => 'fa-chevron-right',
311 'core:t/block_to_dock' => 'fa-chevron-left',
76b5fe86 312 'core:t/calc_off' => 'fa-calculator', // TODO: Change to better icon once we have stacked icon support or more icons.
95b06c13
DW
313 'core:t/calc' => 'fa-calculator',
314 'core:t/check' => 'fa-check',
315 'core:t/cohort' => 'fa-users',
316 'core:t/collapsed_empty_rtl' => 'fa-plus-square-o',
317 'core:t/collapsed_empty' => 'fa-plus-square-o',
318 'core:t/collapsed_rtl' => 'fa-plus-square',
319 'core:t/collapsed' => 'fa-plus-square',
320 'core:t/contextmenu' => 'fa-cog',
321 'core:t/copy' => 'fa-copy',
322 'core:t/delete' => 'fa-trash',
323 'core:t/dockclose' => 'fa-window-close',
324 'core:t/dock_to_block_rtl' => 'fa-chevron-right',
325 'core:t/dock_to_block' => 'fa-chevron-left',
326 'core:t/download' => 'fa-download',
327 'core:t/down' => 'fa-arrow-down',
328 'core:t/dropdown' => 'fa-cog',
329 'core:t/editinline' => 'fa-pencil',
330 'core:t/edit_menu' => 'fa-cog',
331 'core:t/editstring' => 'fa-pencil',
332 'core:t/edit' => 'fa-cog',
ad056aa2
DW
333 'core:t/emailno' => 'fa-ban',
334 'core:t/email' => 'fa-envelope-o',
95b06c13
DW
335 'core:t/enrolusers' => 'fa-user-plus',
336 'core:t/expanded' => 'fa-caret-down',
ad056aa2 337 'core:t/go' => 'fa-play',
cf7ac868 338 'core:t/grades' => 'fa-table',
8857c715
DW
339 'core:t/groupn' => 'fa-user',
340 'core:t/groups' => 'fa-user-circle',
341 'core:t/groupv' => 'fa-user-circle-o',
95b06c13
DW
342 'core:t/hide' => 'fa-eye',
343 'core:t/left' => 'fa-arrow-left',
344 'core:t/less' => 'fa-caret-up',
345 'core:t/locked' => 'fa-lock',
ad056aa2 346 'core:t/lock' => 'fa-unlock',
95b06c13
DW
347 'core:t/locktime' => 'fa-lock',
348 'core:t/markasread' => 'fa-check',
349 'core:t/messages' => 'fa-comments',
350 'core:t/message' => 'fa-comment',
351 'core:t/more' => 'fa-caret-down',
c698b85a 352 'core:t/move' => 'fa-arrows-v',
95b06c13
DW
353 'core:t/passwordunmask-edit' => 'fa-pencil',
354 'core:t/passwordunmask-reveal' => 'fa-eye',
355 'core:t/portfolioadd' => 'fa-plus',
356 'core:t/preferences' => 'fa-wrench',
357 'core:t/preview' => 'fa-search-plus',
358 'core:t/print' => 'fa-print',
359 'core:t/removecontact' => 'fa-user-times',
360 'core:t/reset' => 'fa-repeat',
361 'core:t/restore' => 'fa-arrow-circle-up',
362 'core:t/right' => 'fa-arrow-right',
363 'core:t/show' => 'fa-eye-slash',
364 'core:t/sort_asc' => 'fa-sort-asc',
365 'core:t/sort_desc' => 'fa-sort-desc',
366 'core:t/sort' => 'fa-sort',
367 'core:t/stop' => 'fa-stop',
368 'core:t/switch_minus' => 'fa-minus',
369 'core:t/switch_plus' => 'fa-plus',
370 'core:t/switch_whole' => 'fa-square-o',
371 'core:t/unblock' => 'fa-commenting',
372 'core:t/unlocked' => 'fa-unlock-alt',
373 'core:t/unlock' => 'fa-unlock',
374 'core:t/up' => 'fa-arrow-up',
375 'core:t/user' => 'fa-user',
376 'core:t/viewdetails' => 'fa-list',
377 ];
378 }
e330b1c2 379
e330b1c2
DW
380 /**
381 * Overridable function to get a mapping of all icons.
382 * Default is to do no mapping.
383 */
384 public function get_icon_name_map() {
385 if ($this->map === []) {
7e8940b5 386 $cache = \cache::make('core', 'fontawesomeiconmapping');
e330b1c2 387
7e8940b5
DW
388 $this->map = $cache->get('mapping');
389
390 if (empty($this->map)) {
391 $this->map = $this->get_core_icon_map();
392 $callback = 'get_fontawesome_icon_map';
393
394 if ($pluginsfunction = get_plugins_with_function($callback)) {
395 foreach ($pluginsfunction as $plugintype => $plugins) {
396 foreach ($plugins as $pluginfunction) {
397 $pluginmap = $pluginfunction();
398 $this->map += $pluginmap;
399 }
e330b1c2
DW
400 }
401 }
7e8940b5 402 $cache->set('mapping', $this->map);
e330b1c2
DW
403 }
404
405 }
406 return $this->map;
407 }
408
409
410 public function get_amd_name() {
411 return 'core/icon_system_fontawesome';
412 }
413
414 public function render_pix_icon(renderer_base $output, pix_icon $icon) {
415 $subtype = 'pix_icon_fontawesome';
416 $subpix = new $subtype($icon);
8626dc99 417
e330b1c2
DW
418 $data = $subpix->export_for_template($output);
419
8626dc99
DW
420 if (!$subpix->is_mapped()) {
421 $data['unmappedIcon'] = $icon->export_for_template($output);
422 }
e330b1c2
DW
423 return $output->render_from_template('core/pix_icon_fontawesome', $data);
424 }
425
95b06c13
DW
426}
427