‪TYPO3CMS  10.4
IconViewHelper.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 
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25 
56 class ‪IconViewHelper extends AbstractViewHelper
57 {
58  use CompileWithRenderStatic;
59 
65  protected ‪$escapeOutput = false;
66 
70  public function ‪initializeArguments()
71  {
72  $this->registerArgument('identifier', 'string', 'Identifier of the icon as registered in the Icon Registry.', true);
73  $this->registerArgument('size', 'string', 'Desired size of the icon. All values of the Icons.sizes enum are allowed, these are: "small", "default", "large" and "overlay".', false, ‪Icon::SIZE_SMALL);
74  $this->registerArgument('overlay', 'string', 'Identifier of an overlay icon as registered in the Icon Registry.', false, null);
75  $this->registerArgument('state', 'string', 'Sets the state of the icon. All values of the Icons.states enum are allowed, these are: "default" and "disabled".', false, ‪IconState::STATE_DEFAULT);
76  $this->registerArgument('alternativeMarkupIdentifier', 'string', 'Alternative icon identifier. Takes precedence over the identifier if supported by the IconProvider.', false, null);
77  }
78 
87  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
88  {
89  $identifier = $arguments['identifier'];
90  $size = $arguments['size'];
91  $overlay = $arguments['overlay'];
92  $state = ‪IconState::cast($arguments['state']);
93  $alternativeMarkupIdentifier = $arguments['alternativeMarkupIdentifier'];
94  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
95  return $iconFactory->getIcon($identifier, $size, $overlay, $state)->render($alternativeMarkupIdentifier);
96  }
97 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: IconViewHelper.php:85
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Core\Type\Icon\IconState\STATE_DEFAULT
‪const STATE_DEFAULT
Definition: IconState.php:30
‪TYPO3\CMS\Core\ViewHelpers
‪TYPO3\CMS\Core\Type\Icon\IconState
Definition: IconState.php:24
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: IconViewHelper.php:63
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper
Definition: IconViewHelper.php:57
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper\initializeArguments
‪initializeArguments()
Definition: IconViewHelper.php:68