‪TYPO3CMS  ‪main
IconViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\CMS\Core\Imaging\IconSize;
24 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
27 
58 final class ‪IconViewHelper extends AbstractViewHelper
59 {
60  use CompileWithRenderStatic;
61 
67  protected ‪$escapeOutput = false;
68 
69  public function ‪initializeArguments(): void
70  {
71  $this->registerArgument('identifier', 'string', 'Identifier of the icon as registered in the Icon Registry.', true);
72  $this->registerArgument('size', 'string', 'Desired size of the icon. All values of the IconSize enum are allowed, these are: "small", "default", "medium", "large" and "mega".', false, IconSize::SMALL->value);
73  $this->registerArgument('overlay', 'string', 'Identifier of an overlay icon as registered in the Icon Registry.');
74  $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->value);
75  $this->registerArgument('alternativeMarkupIdentifier', 'string', 'Alternative icon identifier. Takes precedence over the identifier if supported by the IconProvider.');
76  $this->registerArgument('title', 'string', 'Title for the icon');
77  }
78 
82  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
83  {
84  ‪$identifier = $arguments['identifier'];
85  $size = IconSize::from($arguments['size']);
86  $overlay = $arguments['overlay'];
87  $state = IconState::tryFrom($arguments['state']);
88  $alternativeMarkupIdentifier = $arguments['alternativeMarkupIdentifier'];
89  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
90  $icon = $iconFactory->getIcon(‪$identifier, $size, $overlay, $state);
91  if ($arguments['title'] ?? false) {
92  $icon->setTitle($arguments['title']);
93  }
94  return $icon->render($alternativeMarkupIdentifier);
95  }
96 }
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\ViewHelpers
Definition: IconForRecordViewHelper.php:18
‪TYPO3\CMS\Core\Imaging\IconState
‪IconState
Definition: IconState.php:24
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: IconViewHelper.php:65
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper
Definition: IconViewHelper.php:59
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: IconViewHelper.php:80
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper\initializeArguments
‪initializeArguments()
Definition: IconViewHelper.php:67