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