‪TYPO3CMS  10.4
Icon.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 class ‪Icon
26 {
30  const ‪SIZE_SMALL = 'small'; // 16
31 
35  const ‪SIZE_DEFAULT = 'default'; // 32
36 
40  const ‪SIZE_LARGE = 'large'; // 48
41 
46  const ‪SIZE_OVERLAY = 'overlay';
47 
53  protected ‪$identifier;
54 
60  protected ‪$overlayIcon;
61 
67  protected ‪$size = '';
68 
74  protected ‪$spinning = false;
75 
81  protected ‪$state;
82 
86  protected ‪$dimension;
87 
91  protected ‪$markup;
92 
96  protected ‪$alternativeMarkups = [];
97 
105  public function ‪getMarkup($alternativeMarkupIdentifier = null)
106  {
107  if ($alternativeMarkupIdentifier !== null && isset($this->alternativeMarkups[$alternativeMarkupIdentifier])) {
108  return $this->alternativeMarkups[$alternativeMarkupIdentifier];
109  }
110  return ‪$this->markup;
111  }
112 
116  public function ‪setMarkup(‪$markup)
117  {
118  $this->markup = ‪$markup;
119  }
120 
126  public function ‪getAlternativeMarkup($markupIdentifier)
127  {
128  return $this->alternativeMarkups[$markupIdentifier];
129  }
130 
135  public function ‪setAlternativeMarkup($markupIdentifier, ‪$markup)
136  {
137  $this->alternativeMarkups[$markupIdentifier] = ‪$markup;
138  }
139 
143  public function ‪getIdentifier()
144  {
145  return ‪$this->identifier;
146  }
147 
152  {
153  $this->identifier = ‪$identifier;
154  }
155 
159  public function ‪getOverlayIcon()
160  {
161  return ‪$this->overlayIcon;
162  }
163 
168  {
169  $this->overlayIcon = ‪$overlayIcon;
170  }
171 
175  public function ‪getSize()
176  {
178  }
179 
185  public function ‪setSize(‪$size)
186  {
187  $this->size = ‪$size;
188  $this->dimension = GeneralUtility::makeInstance(Dimension::class, ‪$size);
189  }
190 
194  public function ‪isSpinning()
195  {
196  return ‪$this->spinning;
197  }
198 
202  public function ‪setSpinning(‪$spinning)
203  {
204  $this->spinning = ‪$spinning;
205  }
206 
210  public function ‪getState()
211  {
213  }
214 
221  {
222  $this->state = ‪$state;
223  }
224 
228  public function ‪getDimension()
229  {
230  return ‪$this->dimension;
231  }
232 
240  public function ‪render($alternativeMarkupIdentifier = null)
241  {
242  $overlayIconMarkup = '';
243  if ($this->overlayIcon !== null) {
244  $overlayIconMarkup = '<span class="icon-overlay icon-' . htmlspecialchars($this->overlayIcon->getIdentifier()) . '">' . $this->overlayIcon->getMarkup() . '</span>';
245  }
246  return str_replace('{overlayMarkup}', $overlayIconMarkup, $this->‪wrappedIcon($alternativeMarkupIdentifier));
247  }
248 
254  public function ‪__toString()
255  {
256  return $this->‪render();
257  }
258 
266  protected function ‪wrappedIcon($alternativeMarkupIdentifier = null)
267  {
268  $classes = [];
269  $classes[] = 't3js-icon';
270  $classes[] = 'icon';
271  $classes[] = 'icon-size-' . ‪$this->size;
272  $classes[] = 'icon-state-' . htmlspecialchars((string)$this->state);
273  $classes[] = 'icon-' . $this->‪getIdentifier();
274  if ($this->‪isSpinning()) {
275  $classes[] = 'icon-spin';
276  }
277 
278  ‪$markup = [];
279  ‪$markup[] = '<span class="' . htmlspecialchars(implode(' ', $classes)) . '" data-identifier="' . htmlspecialchars($this->‪getIdentifier()) . '">';
280  ‪$markup[] = ' <span class="icon-markup">';
281  ‪$markup[] = $this->‪getMarkup($alternativeMarkupIdentifier);
282  ‪$markup[] = ' </span>';
283  ‪$markup[] = ' {overlayMarkup}';
284  ‪$markup[] = '</span>';
285 
286  return implode(LF, ‪$markup);
287  }
288 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\Imaging\Icon\$spinning
‪bool $spinning
Definition: Icon.php:70
‪TYPO3\CMS\Core\Imaging\Icon\$identifier
‪string $identifier
Definition: Icon.php:52
‪TYPO3\CMS\Core\Imaging\Icon\setIdentifier
‪setIdentifier($identifier)
Definition: Icon.php:143
‪TYPO3\CMS\Core\Imaging
Definition: Dimension.php:16
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_DEFAULT
‪const SIZE_DEFAULT
Definition: Icon.php:35
‪TYPO3\CMS\Core\Imaging\Icon\$size
‪string $size
Definition: Icon.php:64
‪TYPO3\CMS\Core\Imaging\Icon\setOverlayIcon
‪setOverlayIcon($overlayIcon)
Definition: Icon.php:159
‪TYPO3\CMS\Core\Imaging\Icon\__toString
‪string __toString()
Definition: Icon.php:246
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Imaging\Icon\render
‪string render($alternativeMarkupIdentifier=null)
Definition: Icon.php:232
‪TYPO3\CMS\Core\Imaging\Icon\$state
‪IconState $state
Definition: Icon.php:76
‪TYPO3\CMS\Core\Imaging\Icon\isSpinning
‪bool isSpinning()
Definition: Icon.php:186
‪TYPO3\CMS\Core\Imaging\Icon\setState
‪setState(IconState $state)
Definition: Icon.php:212
‪TYPO3\CMS\Core\Imaging\Icon\getMarkup
‪string getMarkup($alternativeMarkupIdentifier=null)
Definition: Icon.php:97
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_OVERLAY
‪const SIZE_OVERLAY
Definition: Icon.php:46
‪TYPO3\CMS\Core\Imaging\Icon\getIdentifier
‪string getIdentifier()
Definition: Icon.php:135
‪TYPO3\CMS\Core\Imaging\Icon\getOverlayIcon
‪Icon getOverlayIcon()
Definition: Icon.php:151
‪TYPO3\CMS\Core\Imaging\Icon\setSize
‪setSize($size)
Definition: Icon.php:177
‪TYPO3\CMS\Core\Imaging\Dimension
Definition: Dimension.php:22
‪TYPO3\CMS\Core\Imaging\Icon\getSize
‪string getSize()
Definition: Icon.php:167
‪TYPO3\CMS\Core\Imaging\Icon\setMarkup
‪setMarkup($markup)
Definition: Icon.php:108
‪TYPO3\CMS\Core\Imaging\Icon\getAlternativeMarkup
‪string getAlternativeMarkup($markupIdentifier)
Definition: Icon.php:118
‪TYPO3\CMS\Core\Imaging\Icon\setSpinning
‪setSpinning($spinning)
Definition: Icon.php:194
‪TYPO3\CMS\Core\Imaging\Icon\$overlayIcon
‪Icon $overlayIcon
Definition: Icon.php:58
‪TYPO3\CMS\Core\Type\Icon\IconState
Definition: IconState.php:24
‪TYPO3\CMS\Core\Imaging\Icon\getDimension
‪Dimension getDimension()
Definition: Icon.php:220
‪TYPO3\CMS\Core\Imaging\Icon\$markup
‪string $markup
Definition: Icon.php:84
‪TYPO3\CMS\Core\Imaging\Icon\wrappedIcon
‪string wrappedIcon($alternativeMarkupIdentifier=null)
Definition: Icon.php:258
‪TYPO3\CMS\Core\Imaging\Icon\setAlternativeMarkup
‪setAlternativeMarkup($markupIdentifier, $markup)
Definition: Icon.php:127
‪TYPO3\CMS\Core\Imaging\Icon\$dimension
‪Dimension $dimension
Definition: Icon.php:80
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_LARGE
‪const SIZE_LARGE
Definition: Icon.php:40
‪TYPO3\CMS\Core\Imaging\Icon\getState
‪IconState getState()
Definition: Icon.php:202
‪TYPO3\CMS\Core\Imaging\Icon\$alternativeMarkups
‪array $alternativeMarkups
Definition: Icon.php:88