‪TYPO3CMS  9.5
Icon.php
Go to the documentation of this file.
1 <?php
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;
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 
151  {
152  $this->identifier = ‪$identifier;
153  }
154 
158  public function ‪getOverlayIcon()
159  {
160  return ‪$this->overlayIcon;
161  }
162 
167  {
168  $this->overlayIcon = ‪$overlayIcon;
169  }
170 
174  public function ‪getSize()
175  {
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  {
212  }
213 
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 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Core\Imaging\Icon\$spinning
‪bool $spinning
Definition: Icon.php:69
‪TYPO3\CMS\Core\Imaging\Icon\$identifier
‪string $identifier
Definition: Icon.php:51
‪TYPO3\CMS\Core\Imaging\Icon\setIdentifier
‪setIdentifier($identifier)
Definition: Icon.php:142
‪TYPO3\CMS\Core\Imaging
Definition: Dimension.php:2
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_DEFAULT
‪const SIZE_DEFAULT
Definition: Icon.php:34
‪TYPO3\CMS\Core\Imaging\Icon\$size
‪string $size
Definition: Icon.php:63
‪TYPO3\CMS\Core\Imaging\Icon\setOverlayIcon
‪setOverlayIcon($overlayIcon)
Definition: Icon.php:158
‪TYPO3\CMS\Core\Imaging\Icon\__toString
‪string __toString()
Definition: Icon.php:245
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Core\Imaging\Icon\render
‪string render($alternativeMarkupIdentifier=null)
Definition: Icon.php:231
‪TYPO3\CMS\Core\Imaging\Icon\$state
‪IconState $state
Definition: Icon.php:75
‪TYPO3\CMS\Core\Imaging\Icon\isSpinning
‪bool isSpinning()
Definition: Icon.php:185
‪TYPO3\CMS\Core\Imaging\Icon\setState
‪setState(IconState $state)
Definition: Icon.php:211
‪TYPO3\CMS\Core\Imaging\Icon\getMarkup
‪string getMarkup($alternativeMarkupIdentifier=null)
Definition: Icon.php:96
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_OVERLAY
‪const SIZE_OVERLAY
Definition: Icon.php:45
‪TYPO3\CMS\Core\Imaging\Icon\getIdentifier
‪string getIdentifier()
Definition: Icon.php:134
‪TYPO3\CMS\Core\Imaging\Icon\getOverlayIcon
‪Icon getOverlayIcon()
Definition: Icon.php:150
‪TYPO3\CMS\Core\Imaging\Icon\setSize
‪setSize($size)
Definition: Icon.php:176
‪TYPO3\CMS\Core\Imaging\Dimension
Definition: Dimension.php:21
‪TYPO3\CMS\Core\Imaging\Icon\getSize
‪string getSize()
Definition: Icon.php:166
‪TYPO3\CMS\Core\Imaging\Icon\setMarkup
‪setMarkup($markup)
Definition: Icon.php:107
‪TYPO3\CMS\Core\Imaging\Icon\getAlternativeMarkup
‪string getAlternativeMarkup($markupIdentifier)
Definition: Icon.php:117
‪TYPO3\CMS\Core\Imaging\Icon\setSpinning
‪setSpinning($spinning)
Definition: Icon.php:193
‪TYPO3\CMS\Core\Imaging\Icon\$overlayIcon
‪Icon $overlayIcon
Definition: Icon.php:57
‪TYPO3\CMS\Core\Type\Icon\IconState
Definition: IconState.php:23
‪TYPO3\CMS\Core\Imaging\Icon\getDimension
‪Dimension getDimension()
Definition: Icon.php:219
‪TYPO3\CMS\Core\Imaging\Icon\$markup
‪string $markup
Definition: Icon.php:83
‪TYPO3\CMS\Core\Imaging\Icon\wrappedIcon
‪string wrappedIcon($alternativeMarkupIdentifier=null)
Definition: Icon.php:257
‪TYPO3\CMS\Core\Imaging\Icon\setAlternativeMarkup
‪setAlternativeMarkup($markupIdentifier, $markup)
Definition: Icon.php:126
‪TYPO3\CMS\Core\Imaging\Icon\$dimension
‪Dimension $dimension
Definition: Icon.php:79
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_LARGE
‪const SIZE_LARGE
Definition: Icon.php:39
‪TYPO3\CMS\Core\Imaging\Icon\getState
‪IconState getState()
Definition: Icon.php:201
‪TYPO3\CMS\Core\Imaging\Icon\$alternativeMarkups
‪array $alternativeMarkups
Definition: Icon.php:87