[TASK] Replace sprite icon "actions-edit-undo" with IconFactory
[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 text-danger',
129 )
130 ),
131 'actions-edit-cut' => array(
132 'provider' => FontawesomeIconProvider::class,
133 'options' => array(
134 'name' => 'scissors',
135 )
136 ),
137 'actions-edit-cut-release' => array(
138 'provider' => FontawesomeIconProvider::class,
139 'options' => array(
140 'name' => 'scissors text-danger',
141 )
142 ),
143 'actions-edit-download' => array(
144 'provider' => FontawesomeIconProvider::class,
145 'options' => array(
146 'name' => 'download',
147 )
148 ),
149 'actions-edit-delete' => array(
150 'provider' => FontawesomeIconProvider::class,
151 'options' => array(
152 'name' => 'trash',
153 )
154 ),
155 'actions-edit-pick-date' => array(
156 'provider' => FontawesomeIconProvider::class,
157 'options' => array(
158 'name' => 'calendar',
159 )
160 ),
161 'actions-edit-replace' => array(
162 'provider' => FontawesomeIconProvider::class,
163 'options' => array(
164 'name' => 'retweet',
165 )
166 ),
167 'actions-edit-undo' => array(
168 'provider' => FontawesomeIconProvider::class,
169 'options' => array(
170 'name' => 'undo',
171 )
172 ),
173
174 // OVERLAYS
175 'overlay-read-only' => array(
176 'provider' => FontawesomeIconProvider::class,
177 'options' => array(
178 'name' => 'minus-circle',
179 )
180 ),
181 );
182
183 /**
184 * @var string
185 */
186 protected $defaultIconIdentifier = 'default-not-found';
187
188 /**
189 * @param $identifier
190 *
191 * @return bool
192 */
193 public function isRegistered($identifier) {
194 return !empty($this->icons[$identifier]);
195 }
196
197 /**
198 * @return string
199 */
200 public function getDefaultIconIdentifier() {
201 return $this->defaultIconIdentifier;
202 }
203
204 /**
205 * Registers an icon to be available inside the Icon Factory
206 *
207 * @param string $identifier
208 * @param string $iconProviderClassName
209 * @param array $options
210 *
211 * @throws \InvalidArgumentException
212 */
213 public function registerIcon($identifier, $iconProviderClassName, array $options = array()) {
214 if (!in_array(IconProviderInterface::class, class_implements($iconProviderClassName), TRUE)) {
215 throw new \InvalidArgumentException('An IconProvider must implement ' . IconProviderInterface::class, 1437425803);
216 }
217 $this->icons[$identifier] = array(
218 'provider' => $iconProviderClassName,
219 'options' => $options
220 );
221 }
222
223 /**
224 * Fetches the configuration provided by registerIcon()
225 *
226 * @param string $identifier the icon identifier
227 * @return mixed
228 * @throws Exception
229 */
230 public function getIconConfigurationByIdentifier($identifier) {
231 if (!$this->isRegistered($identifier)) {
232 throw new Exception('Icon with identifier "' . $identifier . '" is not registered"', 1437425804);
233 }
234 return $this->icons[$identifier];
235 }
236 }