TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Icon.php
Go to the documentation of this file.
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 
19 
24 class Icon
25 {
29  const SIZE_SMALL = 'small'; // 16
30 
34  const SIZE_DEFAULT = 'default'; // 32
35 
39  const SIZE_LARGE = 'large'; // 48
40 
45  const SIZE_OVERLAY = 'overlay';
46 
52  protected $identifier;
53 
59  protected $overlayIcon = null;
60 
66  protected $size = '';
67 
73  protected $spinning = false;
74 
80  protected $state;
81 
85  protected $dimension;
86 
90  protected $markup;
91 
95  protected $alternativeMarkups = [];
96 
104  public function getMarkup($alternativeMarkupIdentifier = null)
105  {
106  if ($alternativeMarkupIdentifier !== null && isset($this->alternativeMarkups[$alternativeMarkupIdentifier])) {
107  return $this->alternativeMarkups[$alternativeMarkupIdentifier];
108  }
109  return $this->markup;
110  }
111 
115  public function setMarkup($markup)
116  {
117  $this->markup = $markup;
118  }
119 
125  public function getAlternativeMarkup($markupIdentifier)
126  {
127  return $this->alternativeMarkups[$markupIdentifier];
128  }
129 
134  public function setAlternativeMarkup($markupIdentifier, $markup)
135  {
136  $this->alternativeMarkups[$markupIdentifier] = $markup;
137  }
138 
142  public function getIdentifier()
143  {
144  return $this->identifier;
145  }
146 
150  public function setIdentifier($identifier)
151  {
152  $this->identifier = $identifier;
153  }
154 
158  public function getOverlayIcon()
159  {
160  return $this->overlayIcon;
161  }
162 
166  public function setOverlayIcon($overlayIcon)
167  {
168  $this->overlayIcon = $overlayIcon;
169  }
170 
174  public function getSize()
175  {
176  return $this->size;
177  }
178 
184  public function setSize($size)
185  {
186  $this->size = $size;
187  $this->dimension = GeneralUtility::makeInstance(Dimension::class, $size);
188  }
189 
193  public function isSpinning()
194  {
195  return $this->spinning;
196  }
197 
201  public function setSpinning($spinning)
202  {
203  $this->spinning = $spinning;
204  }
205 
209  public function getState()
210  {
211  return $this->state;
212  }
213 
219  public function setState(IconState $state)
220  {
221  $this->state = $state;
222  }
223 
227  public function getDimension()
228  {
229  return $this->dimension;
230  }
231 
239  public function render($alternativeMarkupIdentifier = null)
240  {
241  $overlayIconMarkup = '';
242  if ($this->overlayIcon !== null) {
243  $overlayIconMarkup = '<span class="icon-overlay icon-' . htmlspecialchars($this->overlayIcon->getIdentifier()) . '">' . $this->overlayIcon->getMarkup() . '</span>';
244  }
245  return str_replace('{overlayMarkup}', $overlayIconMarkup, $this->wrappedIcon($alternativeMarkupIdentifier));
246  }
247 
253  public function __toString()
254  {
255  return $this->render();
256  }
257 
265  protected function wrappedIcon($alternativeMarkupIdentifier = null)
266  {
267  $classes = [];
268  $classes[] = 't3js-icon';
269  $classes[] = 'icon';
270  $classes[] = 'icon-size-' . $this->size;
271  $classes[] = 'icon-state-' . htmlspecialchars((string)$this->state);
272  $classes[] = 'icon-' . $this->getIdentifier();
273  if ($this->isSpinning()) {
274  $classes[] = 'icon-spin';
275  }
276 
277  $markup = [];
278  $markup[] = '<span class="' . htmlspecialchars(implode(' ', $classes)) . '" data-identifier="' . htmlspecialchars($this->getIdentifier()) . '">';
279  $markup[] = ' <span class="icon-markup">';
280  $markup[] = $this->getMarkup($alternativeMarkupIdentifier);
281  $markup[] = ' </span>';
282  $markup[] = ' {overlayMarkup}';
283  $markup[] = '</span>';
284 
285  return implode(LF, $markup);
286  }
287 }
setState(IconState $state)
Definition: Icon.php:219
setSpinning($spinning)
Definition: Icon.php:201
setAlternativeMarkup($markupIdentifier, $markup)
Definition: Icon.php:134
getAlternativeMarkup($markupIdentifier)
Definition: Icon.php:125
setOverlayIcon($overlayIcon)
Definition: Icon.php:166
wrappedIcon($alternativeMarkupIdentifier=null)
Definition: Icon.php:265
setIdentifier($identifier)
Definition: Icon.php:150
static makeInstance($className,...$constructorArguments)
getMarkup($alternativeMarkupIdentifier=null)
Definition: Icon.php:104
render($alternativeMarkupIdentifier=null)
Definition: Icon.php:239