[TASK] Remove ErrorIconViewHelper and move logic into model and template 63/55763/6
authorGeorg Ringer <georg.ringer@gmail.com>
Fri, 16 Feb 2018 18:53:36 +0000 (19:53 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 19 Feb 2018 19:51:30 +0000 (20:51 +0100)
Simplify generation of the error icon by removing the ViewHelper and
generate the icon identifier in the model instead.

As the ViewHelper is no public API it can be removed without a RST file.

Resolves: #83945
Releases: master
Change-Id: I7515ff69a729ccb66288437f5236a1ce8fa591c1
Reviewed-on: https://review.typo3.org/55763
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/belog/Classes/Domain/Model/LogEntry.php
typo3/sysext/belog/Classes/ViewHelpers/ErrorIconViewHelper.php [deleted file]
typo3/sysext/belog/Resources/Private/Partials/Content/LogEntries.html

index ab1ea1e..a71818a 100644 (file)
@@ -279,6 +279,24 @@ class LogEntry extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
     }
 
     /**
+     * Get class name for the error code
+     *
+     * @return string
+     */
+    public function getErrorIconClass(): string
+    {
+        switch ($this->getError()) {
+            case 1:
+                return 'status-dialog-warning';
+            case 2:
+            case 3:
+                return 'status-dialog-error';
+            default:
+                return 'empty-empty';
+        }
+    }
+
+    /**
      * Set details
      *
      * @param string $details
diff --git a/typo3/sysext/belog/Classes/ViewHelpers/ErrorIconViewHelper.php b/typo3/sysext/belog/Classes/ViewHelpers/ErrorIconViewHelper.php
deleted file mode 100644 (file)
index db58d08..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-namespace TYPO3\CMS\Belog\ViewHelpers;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Core\Imaging\Icon;
-use TYPO3\CMS\Core\Imaging\IconFactory;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
-use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
-use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
-
-/**
- * Display error icon from error integer value
- * @internal
- */
-class ErrorIconViewHelper extends AbstractBackendViewHelper
-{
-    use CompileWithRenderStatic;
-
-    /**
-     * As this ViewHelper renders HTML, the output must not be escaped.
-     *
-     * @var bool
-     */
-    protected $escapeOutput = false;
-
-    /**
-     * Initializes the arguments
-     */
-    public function initializeArguments()
-    {
-        parent::initializeArguments();
-        $this->registerArgument('errorNumber', 'int', 'The error number (0 ... 3)', false, 0);
-    }
-
-    /**
-     * Renders an error icon link as known from the TYPO3 backend.
-     * Error codes 2 and three are mapped to "error" and 1 is mapped to "warning".
-     *
-     * @param array $arguments
-     * @param \Closure $renderChildrenClosure
-     * @param RenderingContextInterface $renderingContext
-     *
-     * @return string
-     */
-    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
-    {
-        $errorSymbols = [
-            '0' => '',
-            '1' => 'status-dialog-warning',
-            '2' => 'status-dialog-error',
-            '3' => 'status-dialog-error'
-        ];
-        if ($errorSymbols[$arguments['errorNumber']]) {
-            $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
-            return $iconFactory->getIcon($errorSymbols[$arguments['errorNumber']], Icon::SIZE_SMALL)->render();
-        }
-        return '';
-    }
-}
index 5c832fc..d9b051f 100644 (file)
                                                <f:for each="{day}" as="logItem">
                                                        <tr>
                                                                <td>
-                                                                       <belog:ErrorIcon errorNumber="{logItem.error}"/>
+                                                                       <f:if condition="{logItem.errorIconClass}">
+                                                                               <core:icon identifier="{logItem.errorIconClass}" />
+                                                                       </f:if>
                                                                </td>
                                                                <td>
                                                                        <f:format.date format="H:i:s">@{logItem.tstamp}</f:format.date>