ef0fd2b8aba1edc781755f85f32e255391905dba
[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 'actions-document-new' => array(
84 'provider' => FontawesomeIconProvider::class,
85 'options' => array(
86 'name' => 'plus-square',
87 )
88 ),
89 'actions-document-open' => array(
90 'provider' => FontawesomeIconProvider::class,
91 'options' => array(
92 'name' => 'pencil',
93 )
94 ),
95 'actions-document-paste-after' => array(
96 'provider' => FontawesomeIconProvider::class,
97 'options' => array(
98 'name' => 'clipboard',
99 )
100 ),
101 'actions-document-select' => array(
102 'provider' => FontawesomeIconProvider::class,
103 'options' => array(
104 'name' => 'check-square-o',
105 )
106 ),
107 'actions-document-paste-into' => array(
108 'provider' => FontawesomeIconProvider::class,
109 'options' => array(
110 'name' => 'clipboard',
111 )
112 ),
113 'actions-document-view' => array(
114 'provider' => FontawesomeIconProvider::class,
115 'options' => array(
116 'name' => 'desktop',
117 )
118 ),
119 'actions-edit-copy' => array(
120 'provider' => FontawesomeIconProvider::class,
121 'options' => array(
122 'name' => 'copy',
123 )
124 ),
125 'actions-edit-copy-release' => array(
126 'provider' => FontawesomeIconProvider::class,
127 'options' => array(
128 'name' => 'copy',
129 'additionalClasses' => 'text-danger',
130 )
131 ),
132 'actions-edit-cut' => array(
133 'provider' => FontawesomeIconProvider::class,
134 'options' => array(
135 'name' => 'scissors',
136 )
137 ),
138 'actions-edit-cut-release' => array(
139 'provider' => FontawesomeIconProvider::class,
140 'options' => array(
141 'name' => 'scissors',
142 'additionalClasses' => 'text-danger',
143 )
144 ),
145 'actions-edit-download' => array(
146 'provider' => FontawesomeIconProvider::class,
147 'options' => array(
148 'name' => 'download',
149 )
150 ),
151 'actions-edit-delete' => array(
152 'provider' => FontawesomeIconProvider::class,
153 'options' => array(
154 'name' => 'trash',
155 )
156 ),
157 'actions-edit-pick-date' => array(
158 'provider' => FontawesomeIconProvider::class,
159 'options' => array(
160 'name' => 'calendar',
161 )
162 ),
163 'actions-edit-rename' => array(
164 'provider' => FontawesomeIconProvider::class,
165 'options' => array(
166 'name' => 'quote-right',
167 )
168 ),
169 'actions-edit-replace' => array(
170 'provider' => FontawesomeIconProvider::class,
171 'options' => array(
172 'name' => 'retweet',
173 )
174 ),
175 'actions-edit-undo' => array(
176 'provider' => FontawesomeIconProvider::class,
177 'options' => array(
178 'name' => 'undo',
179 )
180 ),
181 'actions-edit-upload' => array(
182 'provider' => FontawesomeIconProvider::class,
183 'options' => array(
184 'name' => 'upload',
185 )
186 ),
187 'actions-markstate' => array(
188 'provider' => FontawesomeIconProvider::class,
189 'options' => array(
190 'name' => 'square-o',
191 )
192 ),
193 'actions-page-open' => array(
194 'provider' => FontawesomeIconProvider::class,
195 'options' => array(
196 'name' => 'pencil-square-o',
197 )
198 ),
199 'actions-system-list-open' => array(
200 'provider' => FontawesomeIconProvider::class,
201 'options' => array(
202 'name' => 'list-alt',
203 )
204 ),
205 'actions-version-open' => array(
206 'provider' => FontawesomeIconProvider::class,
207 'options' => array(
208 'name' => 'refresh',
209 )
210 ),
211 'actions-version-swap-version' => array(
212 'provider' => FontawesomeIconProvider::class,
213 'options' => array(
214 'name' => 'exchange',
215 )
216 ),
217 'actions-unmarkstate' => array(
218 'provider' => FontawesomeIconProvider::class,
219 'options' => array(
220 'name' => 'check-square-o',
221 )
222 ),
223
224 // Status
225 'status-status-current' => array(
226 'provider' => FontawesomeIconProvider::class,
227 'options' => array(
228 'name' => 'caret-right',
229 'additionalClasses' => 'text-danger',
230 )
231 ),
232
233 // Overlays
234 'overlay-read-only' => array(
235 'provider' => FontawesomeIconProvider::class,
236 'options' => array(
237 'name' => 'minus-circle',
238 )
239 ),
240 );
241
242 /**
243 * @var string
244 */
245 protected $defaultIconIdentifier = 'default-not-found';
246
247 /**
248 * @param string $identifier
249 *
250 * @return bool
251 */
252 public function isRegistered($identifier) {
253 return !empty($this->icons[$identifier]);
254 }
255
256 /**
257 * @return string
258 */
259 public function getDefaultIconIdentifier() {
260 return $this->defaultIconIdentifier;
261 }
262
263 /**
264 * Registers an icon to be available inside the Icon Factory
265 *
266 * @param string $identifier
267 * @param string $iconProviderClassName
268 * @param array $options
269 *
270 * @throws \InvalidArgumentException
271 */
272 public function registerIcon($identifier, $iconProviderClassName, array $options = array()) {
273 if (!in_array(IconProviderInterface::class, class_implements($iconProviderClassName), TRUE)) {
274 throw new \InvalidArgumentException('An IconProvider must implement ' . IconProviderInterface::class, 1437425803);
275 }
276 $this->icons[$identifier] = array(
277 'provider' => $iconProviderClassName,
278 'options' => $options
279 );
280 }
281
282 /**
283 * Fetches the configuration provided by registerIcon()
284 *
285 * @param string $identifier the icon identifier
286 * @return mixed
287 * @throws Exception
288 */
289 public function getIconConfigurationByIdentifier($identifier) {
290 if (!$this->isRegistered($identifier)) {
291 throw new Exception('Icon with identifier "' . $identifier . '" is not registered"', 1437425804);
292 }
293 return $this->icons[$identifier];
294 }
295
296 /**
297 * @return array
298 * @internal
299 */
300 public function getAllRegisteredIconIdentifiers() {
301 return array_keys($this->icons);
302 }
303 }