[TASK] Improve IconProviders and remove IconUtility usages 55/43355/5
authorStephan Großberndt <stephan@grossberndt.de>
Tue, 15 Sep 2015 16:26:24 +0000 (18:26 +0200)
committerFrank Nägler <frank.naegler@typo3.org>
Fri, 18 Sep 2015 14:17:18 +0000 (16:17 +0200)
Resolves: #69847
Releases: master
Change-Id: Ia08a654af066241005c80df75d4a64c067d01b23
Reviewed-on: http://review.typo3.org/43355
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/backend/Classes/View/PageLayoutView.php
typo3/sysext/beuser/Classes/ViewHelpers/PermissionsViewHelper.php
typo3/sysext/core/Classes/Imaging/IconFactory.php
typo3/sysext/core/Classes/Imaging/IconProvider/BitmapIconProvider.php
typo3/sysext/core/Classes/Imaging/IconProvider/FontawesomeIconProvider.php
typo3/sysext/core/Classes/Imaging/IconProvider/SvgIconProvider.php
typo3/sysext/core/Classes/Imaging/IconRegistry.php
typo3/sysext/core/Tests/Unit/Imaging/IconProvider/BitmapIconProviderTest.php
typo3/sysext/core/Tests/Unit/Imaging/IconProvider/SvgIconProviderTest.php
typo3/sysext/core/Tests/Unit/Imaging/IconRegistryTest.php
typo3/sysext/taskcenter/Classes/Controller/TaskModuleController.php

index 86fe9cd..5be79e2 100644 (file)
@@ -715,7 +715,7 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
                                $viewLink = '';
                                if (!VersionState::cast($this->getPageLayoutController()->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
                                        $onClick = BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id), '', '', ('&L=' . $lP));
-                                       $viewLink = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL) . '</a>';
+                                       $viewLink = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
                                }
                                // Language overlay page header:
                                if ($lP) {
index 0708a89..c53ac10 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Beuser\ViewHelpers;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
@@ -29,16 +28,6 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
 class PermissionsViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
-        * @var string Cached Css classes for a "granted" icon
-        */
-       static protected $grantedCssClasses = '';
-
-       /**
-        * @var string Cached Css classes for a "denied" icon
-        */
-       static protected $deniedCssClasses = '';
-
-       /**
         * @var array Cached labels for a single permission mask like "Delete page"
         */
        static protected $permissionLabels = array();
@@ -65,15 +54,6 @@ class PermissionsViewHelper extends AbstractViewHelper implements CompilableInte
         * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
         */
        static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
-               // The two main icon classes are static during one call. They trigger relatively expensive
-               // calculation with a signal and object creation and thus make sense to have them cached.
-               if (!static::$grantedCssClasses) {
-                       static::$grantedCssClasses = IconUtility::getSpriteIconClasses('status-status-permission-granted');
-               }
-               if (!static::$deniedCssClasses) {
-                       static::$deniedCssClasses = IconUtility::getSpriteIconClasses('status-status-permission-denied');
-               }
-
                $masks = array(1, 16, 2, 4, 8);
 
                if (empty(static::$permissionLabels)) {
@@ -88,28 +68,20 @@ class PermissionsViewHelper extends AbstractViewHelper implements CompilableInte
                $icon = '';
                foreach ($masks as $mask) {
                        if ($arguments['permission'] & $mask) {
-                               $icon .= '<span' .
-                                       ' title="' . static::$permissionLabels[$mask] . '"' .
-                                       ' class="' . static::$grantedCssClasses . ' change-permission text-success"' .
-                                       ' data-page="' . $arguments['pageId'] . '"' .
-                                       ' data-permissions="' . $arguments['permission'] . '"' .
-                                       ' data-mode="delete"' .
-                                       ' data-who="' . $arguments['scope'] . '"' .
-                                       ' data-bits="' . $mask . '"' .
-                                       ' style="cursor:pointer"' .
-                               '></span>';
+                               $permissionClass = 'fa-check text-success';
+                               $mode = 'delete';
                        } else {
-                               $icon .= '<span' .
-                                       ' title="' . static::$permissionLabels[$mask] . '"' .
-                                       ' class="' . static::$deniedCssClasses . ' change-permission text-danger"' .
-                                       ' data-page="' . $arguments['pageId'] . '"' .
-                                       ' data-permissions="' . $arguments['permission'] . '"' .
-                                       ' data-mode="add"' .
-                                       ' data-who="' . $arguments['scope'] . '"' .
-                                       ' data-bits="' . $mask . '"' .
-                                       ' style="cursor:pointer"' .
-                               '></span>';
+                               $permissionClass = 'fa-times text-danger';
+                               $mode = 'add';
                        }
+                       $icon .= '<span style="cursor:pointer"'
+                               . ' title="' . htmlspecialchars(static::$permissionLabels[$mask]) . '"'
+                               . ' data-page="' . $arguments['pageId'] . '"'
+                               . ' data-permissions="' . $arguments['permission'] . '"'
+                               . ' data-who="' . $arguments['scope'] . '"'
+                               . ' data-bits="' . $mask . '"'
+                               . ' data-mode="' . $mode . '"'
+                               . ' class="t3-icon change-permission fa ' . $permissionClass . '"></span>';
                }
 
                return '<span id="' . $arguments['pageId'] . '_' . $arguments['scope'] . '">' . $icon . '</span>';
index 38a3d93..586730e 100644 (file)
@@ -285,7 +285,6 @@ class IconFactory {
         * @param array $options
         * @param string $iconIdentifier
         * @param string $overlayIdentifier
-        *
         * @return mixed
         * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
         * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
index 0684137..96dff01 100644 (file)
@@ -18,9 +18,10 @@ use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconProviderInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
- * Class BitmapIconProvider which provides icons that are classic <img> tags
+ * Class BitmapIconProvider provides icons that are classic <img> tags using bitmaps as source
  */
 class BitmapIconProvider implements IconProviderInterface {
 
@@ -35,11 +36,22 @@ class BitmapIconProvider implements IconProviderInterface {
        /**
         * @param Icon $icon
         * @param array $options
-        *
         * @return string
+        * @throws \InvalidArgumentException
         */
        protected function generateMarkup(Icon $icon, array $options) {
-               $source = PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName($options['source']));
+               if (empty($options['source'])) {
+                       throw new \InvalidArgumentException('The option "source" is required and must not be empty', 1440754980);
+               }
+
+               $source = $options['source'];
+
+               if (StringUtility::beginsWith($source, 'EXT:') || !StringUtility::beginsWith($source, '/')) {
+                       $source = GeneralUtility::getFileAbsFileName($source);
+               }
+               $source = PathUtility::getAbsoluteWebPath($source);
+
                return '<img src="' . htmlspecialchars($source) . '" width="' . $icon->getDimension()->getWidth() . '" height="' . $icon->getDimension()->getHeight() . '" />';
        }
+
 }
index f337ae6..ef8200c 100644 (file)
@@ -44,6 +44,8 @@ class FontawesomeIconProvider implements IconProviderInterface {
                if (preg_match('/^[a-zA-Z0-9\\-]+$/', $options['name']) !== 1) {
                        throw new \InvalidArgumentException('The option "name" must only contain characters a-z, A-Z, 0-9 or -', 1440754979);
                }
+
                return '<span class="icon-unify"><i class="fa fa-' . htmlspecialchars($options['name']) . '"></i></span>';
        }
+
 }
index ce27745..ea00e9c 100644 (file)
@@ -18,9 +18,10 @@ use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconProviderInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
- * Class SvgIconProvider
+ * Class SvgIconProvider provides icons that are classic <img> tags using vectors as source
  */
 class SvgIconProvider implements IconProviderInterface {
 
@@ -35,11 +36,22 @@ class SvgIconProvider implements IconProviderInterface {
        /**
         * @param Icon $icon
         * @param array $options
-        *
         * @return string
+        * @throws \InvalidArgumentException
         */
        protected function generateMarkup(Icon $icon, array $options) {
-               $source = PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName($options['source']));
-               return '<img src="' . $source . '" width="' . $icon->getDimension()->getWidth() . '" height="' . $icon->getDimension()->getHeight() . '" />';
+               if (empty($options['source'])) {
+                       throw new \InvalidArgumentException('The option "source" is required and must not be empty', 1440754980);
+               }
+
+               $source = $options['source'];
+
+               if (StringUtility::beginsWith($source, 'EXT:') || !StringUtility::beginsWith($source, '/')) {
+                       $source = GeneralUtility::getFileAbsFileName($source);
+               }
+               $source = PathUtility::getAbsoluteWebPath($source);
+
+               return '<img src="' . htmlspecialchars($source) . '" width="' . $icon->getDimension()->getWidth() . '" height="' . $icon->getDimension()->getHeight() . '" />';
        }
+
 }
index eb2ab7b..d7ee87b 100644 (file)
@@ -523,7 +523,7 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface {
                                'source' => 'EXT:backend/Resources/Public/Icons/Action/actions-search.svg',
                        )
                ),
-               'actions-system-backend-user-switch'  => array(
+               'actions-system-backend-user-switch' => array(
                        'provider' => FontawesomeIconProvider::class,
                        'options' => array(
                                'name' => 'sign-out',
index 9b217b3..c3dfd36 100644 (file)
@@ -55,6 +55,14 @@ class BitmapIconProviderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
+       public function prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup() {
+               $this->subject->prepareIconMarkup($this->icon, array('source' => '/fileadmin/foo.png'));
+               $this->assertEquals('<img src="/fileadmin/foo.png" width="16" height="16" />', $this->icon->getMarkup());
+       }
+
+       /**
+        * @test
+        */
        public function prepareIconMarkupEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup() {
                $this->subject->prepareIconMarkup($this->icon, array('source' => 'EXT:core/Resources/Public/Images/foo.png'));
                $this->assertEquals('<img src="typo3/sysext/core/Resources/Public/Images/foo.png" width="16" height="16" />', $this->icon->getMarkup());
index 013ddb6..8600740 100644 (file)
@@ -55,6 +55,14 @@ class SvgIconProviderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
+       public function prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup() {
+               $this->subject->prepareIconMarkup($this->icon, array('source' => '/fileadmin/foo.svg'));
+               $this->assertEquals('<img src="/fileadmin/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
+       }
+
+       /**
+        * @test
+        */
        public function getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup() {
                $this->subject->prepareIconMarkup($this->icon, array('source' => 'EXT:core/Resources/Public/Images/foo.svg'));
                $this->assertEquals('<img src="typo3/sysext/core/Resources/Public/Images/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
index 3a0dde8..1c42e00 100644 (file)
@@ -19,7 +19,7 @@ use TYPO3\CMS\Core\Imaging\IconProviderInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
- * Testcase for \TYPO3\CMS\Core\Imaging\IconRegistry
+ * TestCase for \TYPO3\CMS\Core\Imaging\IconRegistry
  */
 class IconRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
@@ -113,4 +113,14 @@ class IconRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function getAllRegisteredIconIdentifiersReturnsAnArrayWithIconIdentiefiers() {
                $this->assertInternalType('array', $this->subject->getAllRegisteredIconIdentifiers());
        }
+
+       /**
+        * @test
+        */
+       public function getAllRegisteredIconIdentifiersReturnsArrayWithAllRegisteredIconIdentifiers() {
+               $result = $this->subject->getAllRegisteredIconIdentifiers();
+               $this->assertInternalType('array', $result);
+               $this->assertContains('default-not-found', $result);
+       }
+
 }
index baa2a5b..cc24430 100644 (file)
@@ -17,12 +17,12 @@ namespace TYPO3\CMS\Taskcenter\Controller;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Taskcenter\TaskInterface;
 
 /**
@@ -66,7 +66,7 @@ class TaskModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
        public function menuConfig() {
                $this->MOD_MENU = array('mode' => array());
                $this->MOD_MENU['mode']['information'] = $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang.xlf:task_overview');
-               $this->MOD_MENU['mode']['tasks'] =  $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang.xlf:task_tasks');
+               $this->MOD_MENU['mode']['tasks'] = $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang.xlf:task_tasks');
                /* Copied from parent::menuConfig, because parent is hardcoded to menu.function,
                 * however menu.function is already used for the individual tasks.
                 * Therefore we use menu.mode here.
@@ -263,7 +263,7 @@ class TaskModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
                                                        $icon = '<img src="' . $icon . '" title="' . $title . '" alt="' . $title . '" />';
                                                }
                                                if (@is_file($icon)) {
-                                                       $icon = '<img' . IconUtility::skinImg('', $icon, 'width="16" height="16"') . ' title="' . $title . '" alt="' . $title . '" />';
+                                                       $icon = '<img src="' . PathUtility::getAbsoluteWebPath($icon) . '" width="16" height="16" title="' . $title . '" alt="' . $title . '" />';
                                                }
                                        } else {
                                                $icon = $item['icon'];