[TASK] Move ViewHelper arguments to initializeArguments() in ext:belog
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / Classes / ViewHelpers / ErrorIconViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Belog\ViewHelpers;
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
17 use TYPO3\CMS\Core\Imaging\Icon;
18 use TYPO3\CMS\Core\Imaging\IconFactory;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
21 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22
23 /**
24 * Display error icon from error integer value
25 * @internal
26 */
27 class ErrorIconViewHelper extends AbstractBackendViewHelper
28 {
29 /**
30 * As this ViewHelper renders HTML, the output must not be escaped.
31 *
32 * @var bool
33 */
34 protected $escapeOutput = false;
35
36 /**
37 * Initializes the arguments
38 */
39 public function initializeArguments()
40 {
41 parent::initializeArguments();
42 $this->registerArgument('errorNumber', 'int', 'The error number (0 ... 3)', false, 0);
43 }
44
45 /**
46 * Renders an error icon link as known from the TYPO3 backend.
47 * Error codes 2 and three are mapped to "error" and 1 is mapped to "warning".
48 *
49 * @return string the rendered error icon link
50 */
51 public function render()
52 {
53 return static::renderStatic(
54 $this->arguments,
55 $this->buildRenderChildrenClosure(),
56 $this->renderingContext
57 );
58 }
59
60 /**
61 * @param array $arguments
62 * @param \Closure $renderChildrenClosure
63 * @param RenderingContextInterface $renderingContext
64 *
65 * @return string
66 */
67 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
68 {
69 $errorSymbols = array(
70 '0' => '',
71 '1' => 'status-dialog-warning',
72 '2' => 'status-dialog-error',
73 '3' => 'status-dialog-error'
74 );
75 if ($errorSymbols[$arguments['errorNumber']]) {
76 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
77 return $iconFactory->getIcon($errorSymbols[$arguments['errorNumber']], Icon::SIZE_SMALL)->render();
78 } else {
79 return '';
80 }
81 }
82 }