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