3201b68d878f79ae4ffce6a8537fb7f790c8c821
[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\FontawesomeIconProvider;
19
20 /**
21 * Class IconRegistry, which makes it possible to register custom icons
22 * from within an extension.
23 */
24 class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface {
25
26 /**
27 * Registered icons
28 *
29 * @var array
30 */
31 protected $icons = array(
32 // Default icon, fallback
33 'default-not-found' => array(
34 'provider' => FontawesomeIconProvider::class,
35 'options' => array(
36 'name' => 'times-circle',
37 )
38 ),
39
40 // Action icons
41 'actions-document-close' => array(
42 'provider' => FontawesomeIconProvider::class,
43 'options' => array(
44 'name' => 'close',
45 )
46 ),
47 'actions-document-edit-access' => array(
48 'provider' => FontawesomeIconProvider::class,
49 'options' => array(
50 'name' => 'clock-o',
51 )
52 ),
53 'actions-document-export-t3d' => array(
54 'provider' => FontawesomeIconProvider::class,
55 'options' => array(
56 'name' => 'download',
57 )
58 ),
59 'actions-document-history-open' => array(
60 'provider' => FontawesomeIconProvider::class,
61 'options' => array(
62 'name' => 'history',
63 )
64 ),
65 'actions-document-info' => array(
66 'provider' => FontawesomeIconProvider::class,
67 'options' => array(
68 'name' => 'info-circle',
69 )
70 ),
71 'actions-document-import-t3d' => array(
72 'provider' => FontawesomeIconProvider::class,
73 'options' => array(
74 'name' => 'upload',
75 )
76 ),
77 'actions-document-move' => array(
78 'provider' => FontawesomeIconProvider::class,
79 'options' => array(
80 'name' => 'arrows',
81 )
82 ),
83
84 'actions-document-new' => array(
85 'provider' => FontawesomeIconProvider::class,
86 'options' => array(
87 'name' => 'plus-square',
88 )
89 ),
90 'actions-document-open' => array(
91 'provider' => FontawesomeIconProvider::class,
92 'options' => array(
93 'name' => 'pencil',
94 )
95 ),
96 'actions-document-paste-after' => array(
97 'provider' => FontawesomeIconProvider::class,
98 'options' => array(
99 'name' => 'clipboard',
100 )
101 ),
102 'actions-document-view' => array(
103 'provider' => FontawesomeIconProvider::class,
104 'options' => array(
105 'name' => 'desktop',
106 )
107 ),
108 'actions-edit-copy' => array(
109 'provider' => FontawesomeIconProvider::class,
110 'options' => array(
111 'name' => 'copy',
112 )
113 ),
114 'actions-edit-copy-release' => array(
115 'provider' => FontawesomeIconProvider::class,
116 'options' => array(
117 'name' => 'copy text-danger',
118 )
119 ),
120 'actions-edit-cut' => array(
121 'provider' => FontawesomeIconProvider::class,
122 'options' => array(
123 'name' => 'scissors',
124 )
125 ),
126 'actions-edit-cut-release' => array(
127 'provider' => FontawesomeIconProvider::class,
128 'options' => array(
129 'name' => 'scissors text-danger',
130 )
131 ),
132
133 // OVERLAYS
134 'overlay-read-only' => array(
135 'provider' => FontawesomeIconProvider::class,
136 'options' => array(
137 'name' => 'minus-circle',
138 )
139 ),
140 );
141
142 /**
143 * @var string
144 */
145 protected $defaultIconIdentifier = 'default-not-found';
146
147 /**
148 * @param $identifier
149 *
150 * @return bool
151 */
152 public function isRegistered($identifier) {
153 return !empty($this->icons[$identifier]);
154 }
155
156 /**
157 * @return string
158 */
159 public function getDefaultIconIdentifier() {
160 return $this->defaultIconIdentifier;
161 }
162
163 /**
164 * Registers an icon to be available inside the Icon Factory
165 *
166 * @param string $identifier
167 * @param string $iconProviderClassName
168 * @param array $options
169 *
170 * @throws \InvalidArgumentException
171 */
172 public function registerIcon($identifier, $iconProviderClassName, array $options = array()) {
173 if (!in_array(IconProviderInterface::class, class_implements($iconProviderClassName), TRUE)) {
174 throw new \InvalidArgumentException('An IconProvider must implement ' . IconProviderInterface::class, 1437425803);
175 }
176 $this->icons[$identifier] = array(
177 'provider' => $iconProviderClassName,
178 'options' => $options
179 );
180 }
181
182 /**
183 * Fetches the configuration provided by registerIcon()
184 *
185 * @param string $identifier the icon identifier
186 * @return mixed
187 * @throws Exception
188 */
189 public function getIconConfigurationByIdentifier($identifier) {
190 if (!$this->isRegistered($identifier)) {
191 throw new Exception('Icon with identifier "' . $identifier . '" is not registered"', 1437425804);
192 }
193 return $this->icons[$identifier];
194 }
195 }