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