20f56760bb39d098b4cc16ba30cd1a0c68e2bfc7
[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 'actions-document-close' => array(
56 'provider' => FontawesomeIconProvider::class,
57 'options' => array(
58 'name' => 'close',
59 )
60 ),
61 'actions-actions-document-duplicates-select' => array(
62 'provider' => BitmapIconProvider::class,
63 'options' => array(
64 'source' => 'EXT:t3skin/images/icons/actions/document-duplicates-select.png',
65 )
66 ),
67 'actions-document-edit-access' => array(
68 'provider' => FontawesomeIconProvider::class,
69 'options' => array(
70 'name' => 'clock-o',
71 )
72 ),
73 'actions-document-export-t3d' => array(
74 'provider' => FontawesomeIconProvider::class,
75 'options' => array(
76 'name' => 'download',
77 )
78 ),
79 'actions-document-history-open' => array(
80 'provider' => FontawesomeIconProvider::class,
81 'options' => array(
82 'name' => 'history',
83 )
84 ),
85 'actions-document-info' => array(
86 'provider' => FontawesomeIconProvider::class,
87 'options' => array(
88 'name' => 'info-circle',
89 )
90 ),
91 'actions-document-import-t3d' => array(
92 'provider' => FontawesomeIconProvider::class,
93 'options' => array(
94 'name' => 'upload',
95 )
96 ),
97 'actions-document-localize' => array(
98 'provider' => BitmapIconProvider::class,
99 'options' => array(
100 'source' => 'EXT:t3skin/images/icons/actions/document-localize.png',
101 )
102 ),
103 'actions-document-move' => array(
104 'provider' => FontawesomeIconProvider::class,
105 'options' => array(
106 'name' => 'arrows',
107 )
108 ),
109 'actions-document-new' => array(
110 'provider' => FontawesomeIconProvider::class,
111 'options' => array(
112 'name' => 'plus-square',
113 )
114 ),
115 'actions-document-open' => array(
116 'provider' => FontawesomeIconProvider::class,
117 'options' => array(
118 'name' => 'pencil',
119 )
120 ),
121 'actions-document-paste-after' => array(
122 'provider' => FontawesomeIconProvider::class,
123 'options' => array(
124 'name' => 'clipboard',
125 )
126 ),
127 'actions-document-select' => array(
128 'provider' => FontawesomeIconProvider::class,
129 'options' => array(
130 'name' => 'check-square-o',
131 )
132 ),
133 'actions-document-paste-into' => array(
134 'provider' => FontawesomeIconProvider::class,
135 'options' => array(
136 'name' => 'clipboard',
137 )
138 ),
139 'actions-document-save' => array(
140 'provider' => BitmapIconProvider::class,
141 'options' => array(
142 'source' => 'EXT:t3skin/images/icons/actions/document-save.png'
143 )
144 ),
145 'actions-document-save-close' => array(
146 'provider' => BitmapIconProvider::class,
147 'options' => array(
148 'source' => 'EXT:t3skin/images/icons/actions/document-save-close.png'
149 )
150 ),
151 'actions-document-synchronize' => array(
152 'provider' => BitmapIconProvider::class,
153 'options' => array(
154 'source' => 'EXT:t3skin/images/icons/actions/document-synchronize.png'
155 )
156 ),
157 'actions-document-view' => array(
158 'provider' => FontawesomeIconProvider::class,
159 'options' => array(
160 'name' => 'desktop',
161 )
162 ),
163 'actions-edit-copy' => array(
164 'provider' => FontawesomeIconProvider::class,
165 'options' => array(
166 'name' => 'copy',
167 )
168 ),
169 'actions-edit-copy-release' => array(
170 'provider' => FontawesomeIconProvider::class,
171 'options' => array(
172 'name' => 'copy',
173 )
174 ),
175 'actions-edit-cut' => array(
176 'provider' => FontawesomeIconProvider::class,
177 'options' => array(
178 'name' => 'scissors',
179 )
180 ),
181 'actions-edit-cut-release' => array(
182 'provider' => FontawesomeIconProvider::class,
183 'options' => array(
184 'name' => 'scissors',
185 )
186 ),
187 'actions-edit-download' => array(
188 'provider' => FontawesomeIconProvider::class,
189 'options' => array(
190 'name' => 'download',
191 )
192 ),
193 'actions-edit-delete' => array(
194 'provider' => FontawesomeIconProvider::class,
195 'options' => array(
196 'name' => 'trash',
197 )
198 ),
199 'actions-edit-localize-status-low' => array(
200 'provider' => BitmapIconProvider::class,
201 'options' => array(
202 'source' => 'EXT:t3skin/images/icons/actions/edit-localize-status-low.png',
203 )
204 ),
205 'actions-edit-localize-status-high' => array(
206 'provider' => BitmapIconProvider::class,
207 'options' => array(
208 'source' => 'EXT:t3skin/images/icons/actions/edit-localize-status-high.png',
209 )
210 ),
211 'actions-edit-merge-localization' => array(
212 'provider' => BitmapIconProvider::class,
213 'options' => array(
214 'source' => 'EXT:t3skin/images/icons/actions/edit-merge-localization.png',
215 )
216 ),
217 'actions-edit-pick-date' => array(
218 'provider' => FontawesomeIconProvider::class,
219 'options' => array(
220 'name' => 'calendar',
221 )
222 ),
223 'actions-edit-rename' => array(
224 'provider' => FontawesomeIconProvider::class,
225 'options' => array(
226 'name' => 'quote-right',
227 )
228 ),
229 'actions-edit-hide' => array(
230 'provider' => FontawesomeIconProvider::class,
231 'options' => array(
232 'name' => 'toggle-on',
233 )
234 ),
235 'actions-edit-replace' => array(
236 'provider' => FontawesomeIconProvider::class,
237 'options' => array(
238 'name' => 'retweet',
239 )
240 ),
241 'actions-edit-restore' => array(
242 'provider' => BitmapIconProvider::class,
243 'options' => array(
244 'source' => 'EXT:t3skin/images/icons/actions/edit-restore.png',
245 )
246 ),
247 'actions-edit-undo' => array(
248 'provider' => FontawesomeIconProvider::class,
249 'options' => array(
250 'name' => 'undo',
251 )
252 ),
253 'actions-edit-unhide' => array(
254 'provider' => FontawesomeIconProvider::class,
255 'options' => array(
256 'name' => 'toggle-off',
257 )
258 ),
259 'actions-edit-upload' => array(
260 'provider' => FontawesomeIconProvider::class,
261 'options' => array(
262 'name' => 'upload',
263 )
264 ),
265 'actions-insert-record' => array(
266 'provider' => BitmapIconProvider::class,
267 'options' => array(
268 'source' => 'EXT:t3skin/images/icons/actions/insert-record.png',
269 )
270 ),
271 'actions-insert-reference' => array(
272 'provider' => BitmapIconProvider::class,
273 'options' => array(
274 'source' => 'EXT:t3skin/images/icons/actions/insert-reference.png',
275 )
276 ),
277 'actions-markstate' => array(
278 'provider' => FontawesomeIconProvider::class,
279 'options' => array(
280 'name' => 'square-o',
281 )
282 ),
283 'actions-page-open' => array(
284 'provider' => FontawesomeIconProvider::class,
285 'options' => array(
286 'name' => 'pencil-square-o',
287 )
288 ),
289 'actions-system-cache-clear-impact-low' => array(
290 'provider' => SvgIconProvider::class,
291 'options' => array(
292 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-system-cache-clear-impact-low.svg',
293 )
294 ),
295 'actions-system-cache-clear-impact-medium' => array(
296 'provider' => SvgIconProvider::class,
297 'options' => array(
298 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-system-cache-clear-impact-medium.svg',
299 )
300 ),
301 'actions-system-cache-clear-impact-high' => array(
302 'provider' => SvgIconProvider::class,
303 'options' => array(
304 'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-system-cache-clear-impact-high.svg',
305 )
306 ),
307 'actions-system-extension-configure' => array(
308 'provider' => FontawesomeIconProvider::class,
309 'options' => array(
310 'name' => 'gear',
311 )
312 ),
313 'actions-system-extension-download' => array(
314 'provider' => FontawesomeIconProvider::class,
315 'options' => array(
316 'name' => 'download',
317 )
318 ),
319 'actions-system-extension-install' => array(
320 'provider' => FontawesomeIconProvider::class,
321 'options' => array(
322 'name' => 'plus-circle',
323 )
324 ),
325 'actions-system-extension-import' => array(
326 'provider' => FontawesomeIconProvider::class,
327 'options' => array(
328 'name' => 'cloud-download',
329 )
330 ),
331 'actions-system-extension-uninstall' => array(
332 'provider' => FontawesomeIconProvider::class,
333 'options' => array(
334 'name' => 'minus-square',
335 )
336 ),
337 'actions-system-extension-sqldump' => array(
338 'provider' => FontawesomeIconProvider::class,
339 'options' => array(
340 'name' => 'database',
341 )
342 ),
343 'actions-system-extension-update' => array(
344 'provider' => FontawesomeIconProvider::class,
345 'options' => array(
346 'name' => 'refresh',
347 )
348 ),
349 'actions-system-list-open' => array(
350 'provider' => FontawesomeIconProvider::class,
351 'options' => array(
352 'name' => 'list-alt',
353 )
354 ),
355 'actions-version-open' => array(
356 'provider' => FontawesomeIconProvider::class,
357 'options' => array(
358 'name' => 'refresh',
359 )
360 ),
361 'actions-system-refresh' => array(
362 'provider' => FontawesomeIconProvider::class,
363 'options' => array(
364 'name' => 'refresh',
365 )
366 ),
367 'actions-version-swap-version' => array(
368 'provider' => FontawesomeIconProvider::class,
369 'options' => array(
370 'name' => 'exchange',
371 )
372 ),
373 'actions-unmarkstate' => array(
374 'provider' => FontawesomeIconProvider::class,
375 'options' => array(
376 'name' => 'check-square-o',
377 )
378 ),
379 'actions-view-go-back' => array(
380 'provider' => FontawesomeIconProvider::class,
381 'options' => array(
382 'name' => 'angle-double-left',
383 )
384 ),
385 'actions-view-go-up' => array(
386 'provider' => FontawesomeIconProvider::class,
387 'options' => array(
388 'name' => 'level-up',
389 )
390 ),
391 'actions-view-paging-first' => array(
392 'provider' => FontawesomeIconProvider::class,
393 'options' => array(
394 'name' => 'step-backward',
395 )
396 ),
397 'actions-view-paging-last' => array(
398 'provider' => FontawesomeIconProvider::class,
399 'options' => array(
400 'name' => 'step-forward',
401 )
402 ),
403 'actions-view-paging-previous' => array(
404 'provider' => FontawesomeIconProvider::class,
405 'options' => array(
406 'name' => 'arrow-left',
407 )
408 ),
409 'actions-view-paging-next' => array(
410 'provider' => FontawesomeIconProvider::class,
411 'options' => array(
412 'name' => 'arrow-right',
413 )
414 ),
415
416 // Status
417 'status-status-current' => array(
418 'provider' => FontawesomeIconProvider::class,
419 'options' => array(
420 'name' => 'caret-right',
421 )
422 ),
423
424 // Overlays
425 'overlay-read-only' => array(
426 'provider' => FontawesomeIconProvider::class,
427 'options' => array(
428 'name' => 'times-circle',
429 )
430 ),
431 );
432
433 /**
434 * @var string
435 */
436 protected $defaultIconIdentifier = 'default-not-found';
437
438 /**
439 * @param string $identifier
440 *
441 * @return bool
442 */
443 public function isRegistered($identifier) {
444 return !empty($this->icons[$identifier]);
445 }
446
447 /**
448 * @return string
449 */
450 public function getDefaultIconIdentifier() {
451 return $this->defaultIconIdentifier;
452 }
453
454 /**
455 * Registers an icon to be available inside the Icon Factory
456 *
457 * @param string $identifier
458 * @param string $iconProviderClassName
459 * @param array $options
460 *
461 * @throws \InvalidArgumentException
462 */
463 public function registerIcon($identifier, $iconProviderClassName, array $options = array()) {
464 if (!in_array(IconProviderInterface::class, class_implements($iconProviderClassName), TRUE)) {
465 throw new \InvalidArgumentException('An IconProvider must implement ' . IconProviderInterface::class, 1437425803);
466 }
467 $this->icons[$identifier] = array(
468 'provider' => $iconProviderClassName,
469 'options' => $options
470 );
471 }
472
473 /**
474 * Fetches the configuration provided by registerIcon()
475 *
476 * @param string $identifier the icon identifier
477 * @return mixed
478 * @throws Exception
479 */
480 public function getIconConfigurationByIdentifier($identifier) {
481 if (!$this->isRegistered($identifier)) {
482 throw new Exception('Icon with identifier "' . $identifier . '" is not registered"', 1437425804);
483 }
484 return $this->icons[$identifier];
485 }
486
487 /**
488 * @return array
489 * @internal
490 */
491 public function getAllRegisteredIconIdentifiers() {
492 return array_keys($this->icons);
493 }
494 }