[TASK] Use b/w manual icons in Extension Manager 33/44333/5
authorXavier Perseguers <xavier@typo3.org>
Wed, 28 Oct 2015 15:10:42 +0000 (16:10 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 30 Oct 2015 17:48:16 +0000 (18:48 +0100)
Change-Id: I6e4aeafb12ed8bbfed75f868c3ca36fc42788699
Resolves: #71100
Releases: master
Reviewed-on: https://review.typo3.org/44333
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/core/Documentation/Changelog/7.5/Feature-68741-IntroduceNewIconFactoryAsBaseForReplaceTheIconSkinningAPI.rst
typo3/sysext/documentation/Classes/ViewHelpers/FormatsViewHelper.php

index cba49e1..c33c334 100644 (file)
@@ -62,7 +62,8 @@ Register an icon
         * @param string $iconProviderClassName the icon provider class name
         * @param array $options provider specific options, please reference the icon provider class
         */
-       IconRegistry::registerIcon($identifier, $iconProviderClassName, array $options = array());
+       $iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
+       $iconRegistry->registerIcon($identifier, $iconProviderClassName, array $options = array());
 
 
 Use an icon
index 3d4dc36..42d3f27 100644 (file)
@@ -48,6 +48,8 @@ class FormatsViewHelper extends AbstractViewHelper implements CompilableInterfac
     }
 
     /**
+     * Statically renders all format download links.
+     *
      * @param array $arguments
      * @param callable $renderChildrenClosure
      * @param RenderingContextInterface $renderingContext
@@ -59,6 +61,7 @@ class FormatsViewHelper extends AbstractViewHelper implements CompilableInterfac
         /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation */
         $documentTranslation = $arguments['documentTranslation'];
 
+        /** @var IconFactory $iconFactory */
         $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
         $emptyIcon = $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render();
         $icons = array(
@@ -74,33 +77,57 @@ class FormatsViewHelper extends AbstractViewHelper implements CompilableInterfac
             $output .= '<a ';
 
             $uri = '../' . $format->getPath();
+            $documentFormat = $format->getFormat();
             $extension = substr($uri, strrpos($uri, '.') + 1);
             if (strlen($extension) < 5) {
                 // This is direct link to a file
                 $output .= 'href="' . $uri . '" class="btn btn-default"';
+                $iconHtml = static::getIconForFileExtension($extension, $iconFactory);
             } else {
-                $extension = $format->getFormat();
-                if ($extension === 'json') {
-                    $extension = 'js';
-                }
                 $output .= 'href="#" onclick="top.TYPO3.Backend.ContentContainer.setUrl(' . GeneralUtility::quoteJSvalue($uri) . ')" class="btn btn-default"';
+                $iconHtml = static::getIconForFileExtension($documentFormat, $iconFactory);
             }
 
             $xliff = 'LLL:EXT:documentation/Resources/Private/Language/locallang.xlf';
             $title = sprintf(
                 $GLOBALS['LANG']->sL($xliff . ':tx_documentation_domain_model_documentformat.format.title'),
-                $format->getFormat()
+                $documentFormat
             );
             $output .= ' title="' . htmlspecialchars($title) . '">';
-            $spriteIconHtml = $iconFactory->getIconForFileExtension($extension, Icon::SIZE_SMALL)->render();
-            $output .= $spriteIconHtml . '</a>' . LF;
-            $keyFormat = $format->getFormat();
-            if ($keyFormat === 'json') {
+            $output .= $iconHtml . '</a>' . LF;
+            if ($documentFormat === 'json') {
                 // It should take over the place of sxw which will then never be used
-                $keyFormat = 'sxw';
+                $documentFormat = 'sxw';
             }
-            $icons[$keyFormat] = $output;
+            $icons[$documentFormat] = $output;
         }
         return implode('', array_values($icons));
     }
+
+    /**
+     * Returns the icon associated to a given file extension (privileging black and white).
+     *
+     * @param IconFactory $iconFactory
+     * @param string $extension
+     * @return string
+     */
+    protected static function getIconForFileExtension($extension, IconFactory $iconFactory)
+    {
+        switch ($extension) {
+            case 'html':
+            case 'pdf':
+                $iconHtml = $iconFactory->getIcon('actions-file-' . $extension, Icon::SIZE_SMALL)->render();
+                break;
+            case 'sxw':
+                $iconHtml = $iconFactory->getIcon('actions-file-openoffice', Icon::SIZE_SMALL)->render();
+                break;
+            case 'json':
+                $iconHtml = $iconFactory->getIcon('actions-system-extension-documentation', Icon::SIZE_SMALL)->render();
+                break;
+            default:
+                $iconHtml = $iconFactory->getIconForFileExtension($extension, Icon::SIZE_SMALL)->render();;
+        }
+        return $iconHtml;
+    }
+
 }