|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright (C) 2018 |
|
5
|
|
|
* Nathan Boiron <[email protected]> |
|
6
|
|
|
* Romain Canon <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This file is part of the TYPO3 NotiZ project. |
|
9
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
10
|
|
|
* under the terms of the GNU General Public License, either |
|
11
|
|
|
* version 3 of the License, or any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* For the full copyright and license information, see: |
|
14
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace CuyZ\Notiz\ViewHelpers\Core; |
|
18
|
|
|
|
|
19
|
|
|
use Closure; |
|
20
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
|
21
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
|
22
|
|
|
use TYPO3\CMS\Core\Type\Icon\IconState; |
|
23
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
24
|
|
|
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; |
|
25
|
|
|
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; |
|
26
|
|
|
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @deprecated Must be removed when TYPO3 v7 is not supported anymore. |
|
30
|
|
|
* |
|
31
|
|
|
* In TYPO3 v7: <f:be.buttons.icon icon="foo" /> |
|
32
|
|
|
* In TYPO3 v8: <core:icon identifier="foo" /> |
|
33
|
|
|
* This ViewHelper: <nz:core.icon identifier="foo" /> |
|
34
|
|
|
*/ |
|
35
|
|
|
class IconViewHelper extends AbstractBackendViewHelper implements CompilableInterface |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* View helper returns HTML, thus we need to disable output escaping |
|
39
|
|
|
* |
|
40
|
|
|
* @var bool |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $escapeOutput = false; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Initializes the arguments |
|
46
|
|
|
*/ |
|
47
|
|
|
public function initializeArguments() |
|
48
|
|
|
{ |
|
49
|
|
|
parent::initializeArguments(); |
|
50
|
|
|
$this->registerArgument('identifier', 'string', 'the table for the record icon', true); |
|
51
|
|
|
$this->registerArgument('size', 'string', 'the icon size', false, Icon::SIZE_SMALL); |
|
52
|
|
|
$this->registerArgument('overlay', 'string', '', false, null); |
|
53
|
|
|
$this->registerArgument('state', 'string', '', false, IconState::STATE_DEFAULT); |
|
54
|
|
|
$this->registerArgument('alternativeMarkupIdentifier', 'string', '', false, null); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function render() |
|
61
|
|
|
{ |
|
62
|
|
|
return static::renderStatic( |
|
63
|
|
|
$this->arguments, |
|
64
|
|
|
$this->buildRenderChildrenClosure(), |
|
65
|
|
|
$this->renderingContext |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Prints icon html for $identifier key |
|
71
|
|
|
* |
|
72
|
|
|
* @param array $arguments |
|
73
|
|
|
* @param Closure $renderChildrenClosure |
|
74
|
|
|
* @param RenderingContextInterface $renderingContext |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
|
78
|
|
|
{ |
|
79
|
|
|
$identifier = $arguments['identifier']; |
|
80
|
|
|
$size = $arguments['size']; |
|
81
|
|
|
$overlay = $arguments['overlay']; |
|
82
|
|
|
$state = IconState::cast($arguments['state']); |
|
83
|
|
|
$alternativeMarkupIdentifier = $arguments['alternativeMarkupIdentifier']; |
|
84
|
|
|
/** @var IconFactory $iconFactory */ |
|
85
|
|
|
$iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
|
86
|
|
|
return $iconFactory->getIcon($identifier, $size, $overlay, $state)->render($alternativeMarkupIdentifier); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|