[!!!][TASK] Replace sprite icons with IconFactory in ContextMenu
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Imaging / IconRegistry.php
1 <?php
2 namespace TYPO3\CMS\Core\Imaging;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Exception;
18 use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider;
19 use TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider;
20 use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
21
22 /**
23 * Class IconRegistry, which makes it possible to register custom icons
24 * from within an extension.
25 */
26 class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface {
27
28 /**
29 * Registered icons
30 *
31 * @var array
32 */
33 protected $icons = array(
34 // Default icon, fallback
35 'default-not-found' => array(
36 'provider' => FontawesomeIconProvider::class,
37 'options' => array(
38 'name' => 'times-circle',
39 )
40 ),
41
42 // Action icons
43 'apps-toolbar-menu-cache' => array(
44 'provider' => FontawesomeIconProvider::class,
45 'options' => array(
46 'name' => 'bolt',
47 )
48 ),
49 'apps-toolbar-menu-shortcut' => array(
50 'provider' => FontawesomeIconProvider::class,
51 'options' => array(
52 'name' => 'star',
53 )
54 ),
55 'apps-pagetree-root' => array(
56 'provider' => SvgIconProvider::class,
57 'options' => array(
58 'source' => 'EXT:backend/Resources/Public/Icons/App/apps-pagetree-root.svg',
59 )
60 ),
61 'actions-document-close' => array(
62 'provider' => FontawesomeIconProvider::class,
63 'options' => array(
64 'name' => 'close',
65 )
66 ),
67 'actions-actions-document-duplicates-select' => array(
68 'provider' => BitmapIconProvider::class,
69 'options' => array(
70 'source' => 'EXT:t3skin/images/icons/actions/document-duplicates-select.png',
71 )
72 ),
73 'actions-document-edit-access' => array(
74 'provider' => FontawesomeIconProvider::class,
75 'options' => array(
76 'name' => 'clock-o',
77 )
78 ),
79 'actions-document-export-t3d' => array(
80 'provider' => FontawesomeIconProvider::class,
81 'options' => array(
82 'name' => 'download',
83 )
84 ),
85 'actions-document-history-open' => array(
86 'provider' => FontawesomeIconProvider::class,
87 'options' => array(
88 'name' => 'history',
89 )
90 ),
91 'actions-document-info' => array(
92 'provider' => FontawesomeIconProvider::class,
93 'options' => array(
94 'name' => 'info-circle',
95 )
96 ),
97 'actions-document-import-t3d' => array(
98 'provider' => FontawesomeIconProvider::class,
99 'options' => array(
100 'name' => 'upload',
101 )
102 ),
103 'actions-document-localize' => array(
104 'provider' => BitmapIconProvider::class,
105 'options' => array(
106 'source' => 'EXT:t3skin/images/icons/actions/document-localize.png',
107 )
108 ),
109 'actions-document-move' => array(
110 'provider' => FontawesomeIconProvider::class,
111 'options' => array(
112 'name' => 'arrows',
113 )
114 ),
115 'actions-document-new' => array(
116 'provider' => FontawesomeIconProvider::class,
117 'options' => array(
118 'name' => 'plus-square',
119 )
120 ),
121 'actions-document-open' => array(
122 'provider' => FontawesomeIconProvider::class,
123 'options' => array(
124 'name' => 'pencil',
125 )
126 ),
127 'actions-document-paste' => array(
128 'provider' => SvgIconProvider::class,
129 'options' => array(
130 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-paste.svg',
131 )
132 ),
133 'actions-document-paste-after' => array(
134 'provider' => SvgIconProvider::class,
135 'options' => array(
136 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-paste-after.svg',
137 )
138 ),
139 'actions-document-paste-before' => array(
140 'provider' => SvgIconProvider::class,
141 'options' => array(
142 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-paste-before.svg',
143 )
144 ),
145 'actions-document-paste-into' => array(
146 'provider' => SvgIconProvider::class,
147 'options' => array(
148 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-paste-into.svg',
149 )
150 ),
151 'actions-document-select' => array(
152 'provider' => FontawesomeIconProvider::class,
153 'options' => array(
154 'name' => 'check-square-o',
155 )
156 ),
157 'actions-document-save' => array(
158 'provider' => SvgIconProvider::class,
159 'options' => array(
160 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-save.svg',
161 )
162 ),
163 'actions-document-save-cleartranslationcache' => array(
164 'provider' => SvgIconProvider::class,
165 'options' => array(
166 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-save-cleartranslationcache.svg',
167 )
168 ),
169 'actions-document-save-close' => array(
170 'provider' => SvgIconProvider::class,
171 'options' => array(
172 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-save-close.svg',
173 )
174 ),
175 'actions-document-save-new' => array(
176 'provider' => SvgIconProvider::class,
177 'options' => array(
178 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-save-new.svg',
179 )
180 ),
181 'actions-document-save-translation' => array(
182 'provider' => SvgIconProvider::class,
183 'options' => array(
184 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-save-translation.svg',
185 )
186 ),
187 'actions-document-save-view' => array(
188 'provider' => SvgIconProvider::class,
189 'options' => array(
190 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-document-save-view.svg',
191 )
192 ),
193 'actions-document-synchronize' => array(
194 'provider' => BitmapIconProvider::class,
195 'options' => array(
196 'source' => 'EXT:t3skin/images/icons/actions/document-synchronize.png'
197 )
198 ),
199 'actions-document-view' => array(
200 'provider' => FontawesomeIconProvider::class,
201 'options' => array(
202 'name' => 'desktop',
203 )
204 ),
205 'actions-edit-copy' => array(
206 'provider' => FontawesomeIconProvider::class,
207 'options' => array(
208 'name' => 'copy',
209 )
210 ),
211 'actions-edit-copy-release' => array(
212 'provider' => FontawesomeIconProvider::class,
213 'options' => array(
214 'name' => 'copy',
215 )
216 ),
217 'actions-edit-cut' => array(
218 'provider' => FontawesomeIconProvider::class,
219 'options' => array(
220 'name' => 'scissors',
221 )
222 ),
223 'actions-edit-cut-release' => array(
224 'provider' => FontawesomeIconProvider::class,
225 'options' => array(
226 'name' => 'scissors',
227 )
228 ),
229 'actions-edit-download' => array(
230 'provider' => FontawesomeIconProvider::class,
231 'options' => array(
232 'name' => 'download',
233 )
234 ),
235 'actions-edit-add' => array(
236 'provider' => FontawesomeIconProvider::class,
237 'options' => array(
238 'name' => 'plus-circle',
239 )
240 ),
241 'actions-edit-delete' => array(
242 'provider' => FontawesomeIconProvider::class,
243 'options' => array(
244 'name' => 'trash',
245 )
246 ),
247 'actions-edit-localize-status-low' => array(
248 'provider' => BitmapIconProvider::class,
249 'options' => array(
250 'source' => 'EXT:t3skin/images/icons/actions/edit-localize-status-low.png',
251 )
252 ),
253 'actions-edit-localize-status-high' => array(
254 'provider' => BitmapIconProvider::class,
255 'options' => array(
256 'source' => 'EXT:t3skin/images/icons/actions/edit-localize-status-high.png',
257 )
258 ),
259 'actions-edit-merge-localization' => array(
260 'provider' => BitmapIconProvider::class,
261 'options' => array(
262 'source' => 'EXT:t3skin/images/icons/actions/edit-merge-localization.png',
263 )
264 ),
265 'actions-edit-pick-date' => array(
266 'provider' => FontawesomeIconProvider::class,
267 'options' => array(
268 'name' => 'calendar',
269 )
270 ),
271 'actions-edit-rename' => array(
272 'provider' => FontawesomeIconProvider::class,
273 'options' => array(
274 'name' => 'quote-right',
275 )
276 ),
277 'actions-edit-hide' => array(
278 'provider' => FontawesomeIconProvider::class,
279 'options' => array(
280 'name' => 'toggle-on',
281 )
282 ),
283 'actions-edit-replace' => array(
284 'provider' => FontawesomeIconProvider::class,
285 'options' => array(
286 'name' => 'retweet',
287 )
288 ),
289 'actions-edit-restore' => array(
290 'provider' => BitmapIconProvider::class,
291 'options' => array(
292 'source' => 'EXT:t3skin/images/icons/actions/edit-restore.png',
293 )
294 ),
295 'actions-edit-undo' => array(
296 'provider' => FontawesomeIconProvider::class,
297 'options' => array(
298 'name' => 'undo',
299 )
300 ),
301 'actions-edit-unhide' => array(
302 'provider' => FontawesomeIconProvider::class,
303 'options' => array(
304 'name' => 'toggle-off',
305 )
306 ),
307 'actions-edit-upload' => array(
308 'provider' => FontawesomeIconProvider::class,
309 'options' => array(
310 'name' => 'upload',
311 )
312 ),
313 'actions-insert-record' => array(
314 'provider' => BitmapIconProvider::class,
315 'options' => array(
316 'source' => 'EXT:t3skin/images/icons/actions/insert-record.png',
317 )
318 ),
319 'actions-insert-reference' => array(
320 'provider' => BitmapIconProvider::class,
321 'options' => array(
322 'source' => 'EXT:t3skin/images/icons/actions/insert-reference.png',
323 )
324 ),
325 'actions-markstate' => array(
326 'provider' => FontawesomeIconProvider::class,
327 'options' => array(
328 'name' => 'square-o',
329 )
330 ),
331 'actions-page-new' => array(
332 'provider' => SvgIconProvider::class,
333 'options' => array(
334 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-page-new.svg',
335 )
336 ),
337 'actions-page-move' => array(
338 'provider' => SvgIconProvider::class,
339 'options' => array(
340 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-page-move.svg',
341 ),
342 ),
343 'actions-move' => array(
344 'provider' => FontawesomeIconProvider::class,
345 'options' => array(
346 'name' => 'arrows',
347 )
348 ),
349 'actions-move-down' => array(
350 'provider' => FontawesomeIconProvider::class,
351 'options' => array(
352 'name' => 'angle-down',
353 )
354 ),
355 'actions-move-left' => array(
356 'provider' => FontawesomeIconProvider::class,
357 'options' => array(
358 'name' => 'angle-left',
359 )
360 ),
361 'actions-move-move' => array(
362 'provider' => FontawesomeIconProvider::class,
363 'options' => array(
364 'name' => 'bars',
365 )
366 ),
367 'actions-move-right' => array(
368 'provider' => FontawesomeIconProvider::class,
369 'options' => array(
370 'name' => 'angle-right',
371 )
372 ),
373 'actions-move-to-bottom' => array(
374 'provider' => FontawesomeIconProvider::class,
375 'options' => array(
376 'name' => 'angle-double-down',
377 )
378 ),
379 'actions-move-to-top' => array(
380 'provider' => FontawesomeIconProvider::class,
381 'options' => array(
382 'name' => 'angle-double-up',
383 )
384 ),
385 'actions-move-up' => array(
386 'provider' => FontawesomeIconProvider::class,
387 'options' => array(
388 'name' => 'angle-up',
389 )
390 ),
391 'actions-page-open' => array(
392 'provider' => SvgIconProvider::class,
393 'options' => array(
394 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-page-open.svg',
395 )
396 ),
397 'actions-pagetree-collapse' => array(
398 'provider' => FontawesomeIconProvider::class,
399 'options' => array(
400 'name' => 'caret-right',
401 )
402 ),
403 'actions-pagetree-expand' => array(
404 'provider' => FontawesomeIconProvider::class,
405 'options' => array(
406 'name' => 'caret-down',
407 )
408 ),
409 'actions-pagetree-mountroot' => array(
410 'provider' => FontawesomeIconProvider::class,
411 'options' => array(
412 'name' => 'anchor',
413 )
414 ),
415 'actions-selection-delete' => array(
416 'provider' => FontawesomeIconProvider::class,
417 'options' => array(
418 'name' => 'trash',
419 )
420 ),
421 'actions-system-cache-clear-impact-low' => array(
422 'provider' => SvgIconProvider::class,
423 'options' => array(
424 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-system-cache-clear-impact-low.svg',
425 )
426 ),
427 'actions-system-cache-clear-impact-medium' => array(
428 'provider' => SvgIconProvider::class,
429 'options' => array(
430 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-system-cache-clear-impact-medium.svg',
431 )
432 ),
433 'actions-system-cache-clear-impact-high' => array(
434 'provider' => SvgIconProvider::class,
435 'options' => array(
436 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-system-cache-clear-impact-high.svg',
437 )
438 ),
439 'actions-system-help-open' => array(
440 'provider' => SvgIconProvider::class,
441 'options' => array(
442 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-system-help-open.svg',
443 )
444 ),
445 'actions-system-extension-configure' => array(
446 'provider' => FontawesomeIconProvider::class,
447 'options' => array(
448 'name' => 'gear',
449 )
450 ),
451 'actions-system-extension-download' => array(
452 'provider' => FontawesomeIconProvider::class,
453 'options' => array(
454 'name' => 'download',
455 )
456 ),
457 'actions-system-extension-install' => array(
458 'provider' => FontawesomeIconProvider::class,
459 'options' => array(
460 'name' => 'plus-circle',
461 )
462 ),
463 'actions-system-extension-import' => array(
464 'provider' => FontawesomeIconProvider::class,
465 'options' => array(
466 'name' => 'cloud-download',
467 )
468 ),
469 'actions-system-extension-uninstall' => array(
470 'provider' => FontawesomeIconProvider::class,
471 'options' => array(
472 'name' => 'minus-square',
473 )
474 ),
475 'actions-system-extension-sqldump' => array(
476 'provider' => FontawesomeIconProvider::class,
477 'options' => array(
478 'name' => 'database',
479 )
480 ),
481 'actions-system-extension-update' => array(
482 'provider' => FontawesomeIconProvider::class,
483 'options' => array(
484 'name' => 'refresh',
485 )
486 ),
487 'actions-system-list-open' => array(
488 'provider' => FontawesomeIconProvider::class,
489 'options' => array(
490 'name' => 'list-alt',
491 )
492 ),
493 'actions-version-open' => array(
494 'provider' => FontawesomeIconProvider::class,
495 'options' => array(
496 'name' => 'refresh',
497 )
498 ),
499 'actions-system-shortcut-new' => array(
500 'provider' => BitmapIconProvider::class,
501 'options' => array(
502 'source' => 'EXT:t3skin/images/icons/actions/system-shortcut-new.png',
503 )
504 ),
505 'actions-system-refresh' => array(
506 'provider' => FontawesomeIconProvider::class,
507 'options' => array(
508 'name' => 'refresh',
509 )
510 ),
511 'actions-version-swap-version' => array(
512 'provider' => FontawesomeIconProvider::class,
513 'options' => array(
514 'name' => 'exchange',
515 )
516 ),
517 'actions-unmarkstate' => array(
518 'provider' => FontawesomeIconProvider::class,
519 'options' => array(
520 'name' => 'check-square-o',
521 )
522 ),
523 'actions-view-go-back' => array(
524 'provider' => FontawesomeIconProvider::class,
525 'options' => array(
526 'name' => 'angle-double-left',
527 )
528 ),
529 'actions-view-go-up' => array(
530 'provider' => FontawesomeIconProvider::class,
531 'options' => array(
532 'name' => 'level-up',
533 )
534 ),
535 'actions-view-paging-first' => array(
536 'provider' => FontawesomeIconProvider::class,
537 'options' => array(
538 'name' => 'step-backward',
539 )
540 ),
541 'actions-view-paging-last' => array(
542 'provider' => FontawesomeIconProvider::class,
543 'options' => array(
544 'name' => 'step-forward',
545 )
546 ),
547 'actions-view-paging-previous' => array(
548 'provider' => FontawesomeIconProvider::class,
549 'options' => array(
550 'name' => 'arrow-left',
551 )
552 ),
553 'actions-view-paging-next' => array(
554 'provider' => FontawesomeIconProvider::class,
555 'options' => array(
556 'name' => 'arrow-right',
557 )
558 ),
559 'actions-window-open' => array(
560 'provider' => FontawesomeIconProvider::class,
561 'options' => array(
562 'name' => 'arrows-alt',
563 )
564 ),
565
566 // specials
567 'empty-empty' => array(
568 'provider' => FontawesomeIconProvider::class,
569 'options' => array(
570 'name' => 'empty-empty',
571 )
572 ),
573
574 // Miscellaneous icons
575 'miscellaneous-placeholder' => array(
576 'provider' => SvgIconProvider::class,
577 'options' => array(
578 'source' => 'EXT:backend/Resources/Public/Icons/Miscellaneous/miscellaneous-placeholder.svg',
579 )
580 ),
581
582 // Status
583 'status-status-current' => array(
584 'provider' => FontawesomeIconProvider::class,
585 'options' => array(
586 'name' => 'caret-right',
587 )
588 ),
589 'status-status-sorting-asc' => array(
590 'provider' => FontawesomeIconProvider::class,
591 'options' => array(
592 'name' => 'caret-up',
593 )
594 ),
595 'status-status-sorting-desc' => array(
596 'provider' => FontawesomeIconProvider::class,
597 'options' => array(
598 'name' => 'caret-down',
599 )
600 ),
601 'status-status-sorting-light-asc' => array(
602 'provider' => FontawesomeIconProvider::class,
603 'options' => array(
604 'name' => 'caret-up',
605 )
606 ),
607 'status-status-sorting-light-desc' => array(
608 'provider' => FontawesomeIconProvider::class,
609 'options' => array(
610 'name' => 'caret-down',
611 )
612 ),
613 'status-dialog-ok' => array(
614 'provider' => FontawesomeIconProvider::class,
615 'options' => array(
616 'name' => 'check-circle',
617 )
618 ),
619 'status-dialog-notification' => array(
620 'provider' => FontawesomeIconProvider::class,
621 'options' => array(
622 'name' => 'exclamation-circle',
623 )
624 ),
625 'status-dialog-warning' => array(
626 'provider' => FontawesomeIconProvider::class,
627 'options' => array(
628 'name' => 'exclamation-triangle',
629 )
630 ),
631 'status-dialog-error' => array(
632 'provider' => FontawesomeIconProvider::class,
633 'options' => array(
634 'name' => 'exclamation-circle',
635 )
636 ),
637 'status-warning-lock' => array(
638 'provider' => BitmapIconProvider::class,
639 'options' => array(
640 'source' => 'EXT:t3skin/images/icons/status/warning-lock.png',
641 )
642 ),
643 'status-status-permission-granted' => array(
644 'provider' => FontawesomeIconProvider::class,
645 'options' => array(
646 'name' => 'check',
647 )
648 ),
649 'status-status-permission-denied' => array(
650 'provider' => FontawesomeIconProvider::class,
651 'options' => array(
652 'name' => 'times',
653 )
654 ),
655
656 // Mimetypes
657 'mimetypes-text-html' => array(
658 'provider' => FontawesomeIconProvider::class,
659 'options' => array(
660 'name' => 'file-text-o',
661 )
662 ),
663 'mimetypes-word' => array(
664 'provider' => FontawesomeIconProvider::class,
665 'options' => array(
666 'name' => 'file-word-o',
667 )
668 ),
669
670 // Overlays
671 'overlay-read-only' => array(
672 'provider' => FontawesomeIconProvider::class,
673 'options' => array(
674 'name' => 'times-circle',
675 )
676 ),
677 );
678
679 /**
680 * @var string
681 */
682 protected $defaultIconIdentifier = 'default-not-found';
683
684 /**
685 * @param string $identifier
686 *
687 * @return bool
688 */
689 public function isRegistered($identifier) {
690 return !empty($this->icons[$identifier]);
691 }
692
693 /**
694 * @return string
695 */
696 public function getDefaultIconIdentifier() {
697 return $this->defaultIconIdentifier;
698 }
699
700 /**
701 * Registers an icon to be available inside the Icon Factory
702 *
703 * @param string $identifier
704 * @param string $iconProviderClassName
705 * @param array $options
706 *
707 * @throws \InvalidArgumentException
708 */
709 public function registerIcon($identifier, $iconProviderClassName, array $options = array()) {
710 if (!in_array(IconProviderInterface::class, class_implements($iconProviderClassName), TRUE)) {
711 throw new \InvalidArgumentException('An IconProvider must implement ' . IconProviderInterface::class, 1437425803);
712 }
713 $this->icons[$identifier] = array(
714 'provider' => $iconProviderClassName,
715 'options' => $options
716 );
717 }
718
719 /**
720 * Fetches the configuration provided by registerIcon()
721 *
722 * @param string $identifier the icon identifier
723 * @return mixed
724 * @throws Exception
725 */
726 public function getIconConfigurationByIdentifier($identifier) {
727 if (!$this->isRegistered($identifier)) {
728 throw new Exception('Icon with identifier "' . $identifier . '" is not registered"', 1437425804);
729 }
730 return $this->icons[$identifier];
731 }
732
733 /**
734 * @return array
735 * @internal
736 */
737 public function getAllRegisteredIconIdentifiers() {
738 return array_keys($this->icons);
739 }
740 }