[TASK] Add IconUtility::getSpriteIconForResource() 90/27790/5
authorFrans Saris <franssaris@gmail.com>
Sat, 22 Feb 2014 19:48:54 +0000 (20:48 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 28 Feb 2014 18:23:07 +0000 (19:23 +0100)
With the introduction of FAL the files and folders are
objects and so there is more info than just a name/extension
to determine the right icon. And with file_metadata
you have the possibility to even add more info to
a file (access rights etc).

This patch adds a new method to the IconUtility API for
generating the sprite icon for a resource. There is also
a hook where other extensions can hook in and change
the icon, options and overlays.

Furthermore, all calls in the core are changed to
IconUtility::getSpriteIconForFile where a
File or Folder object was available.

Resolves: #56211
Documentation: #56412
Releases: 6.2
Change-Id: Ifae61dd65d690fffd90c66568e2647ebd403bce5
Reviewed-on: https://review.typo3.org/27790
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
Reviewed-by: Markus Klein
Reviewed-by: Stefan Froemken
Tested-by: Stefan Froemken
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/backend/Classes/ClickMenu/ClickMenu.php
typo3/sysext/backend/Classes/Clipboard/Clipboard.php
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/backend/Classes/Tree/View/FolderTreeView.php
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Classes/Utility/IconUtility.php
typo3/sysext/backend/Classes/Utility/IconUtilityOverrideResourceIconHookInterface.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Unit/Utility/IconUtilityTest.php
typo3/sysext/filelist/Classes/FileList.php
typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php

index b652def..b320ca6 100644 (file)
@@ -745,7 +745,7 @@ class ClickMenu {
                        $userMayEditStorage = FALSE;
                        $identifier = $fileObject->getCombinedIdentifier();
                        if ($fileObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
-                               $icon = IconUtility::getSpriteIconForFile('folder', array(
+                               $icon = IconUtility::getSpriteIconForResource($fileObject, array(
                                        'class' => 'absmiddle',
                                        'title' => htmlspecialchars($fileObject->getName())
                                ));
@@ -763,7 +763,7 @@ class ClickMenu {
                                        $isOnline = FALSE;
                                }
                        } else {
-                               $icon = IconUtility::getSpriteIconForFile($fileObject->getExtension(), array(
+                               $icon = IconUtility::getSpriteIconForResource($fileObject, array(
                                        'class' => 'absmiddle',
                                        'title' => htmlspecialchars($fileObject->getName() . ' (' . GeneralUtility::formatSize($fileObject->getSize()) . ')')
                                ));
index da82427..a9c607d 100644 (file)
@@ -364,7 +364,7 @@ class Clipboard {
                                                        $thumb = '';
                                                        $folder = $fileObject instanceof \TYPO3\CMS\Core\Resource\Folder;
                                                        $size = $folder ? '' : '(' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes)';
-                                                       $icon = IconUtility::getSpriteIconForFile($folder ? 'folder' : strtolower($fileObject->getExtension()), array('style' => 'margin: 0 20px;', 'title' => $fileObject->getName() . ' ' . $size));
+                                                       $icon = IconUtility::getSpriteIconForResource($fileObject, array('style' => 'margin: 0 20px;', 'title' => $fileObject->getName() . ' ' . $size));
                                                        if (!$folder && $this->clipData['_setThumb'] && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) {
                                                                $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
                                                                if ($processedFile) {
index c01e5a6..fdd354e 100644 (file)
@@ -2497,7 +2497,7 @@ TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
                                                        $imgs[] = '<span class="nobr">' . $imgTag . htmlspecialchars($fileObject->getName()) . '</span>';
                                                } else {
                                                        // Icon
-                                                       $imgTag = IconUtility::getSpriteIconForFile(strtolower($fileObject->getExtension()), array('title' => $fileObject->getName()));
+                                                       $imgTag = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName()));
                                                        $imgs[] = '<span class="nobr">' . $imgTag . htmlspecialchars($fileObject->getName()) . '</span>';
                                                }
                                        } else {
index a8d07af..f7c43bd 100644 (file)
@@ -299,19 +299,13 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
                        } else {
                                $firstHtml = $icon;
                        }
-                       // @todo: create sprite icons for user/group mounts etc
-                       if ($storageObject->isBrowsable() === FALSE) {
-                               $icon = 'apps-filetree-folder-locked';
-                       } else {
-                               $icon = 'apps-filetree-root';
-                       }
                        // Mark a storage which is not online, as offline
                        // maybe someday there will be a special icon for this
                        if ($storageObject->isOnline() === FALSE) {
                                $rootLevelFolderName .= ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file.xlf:sys_file_storage.isOffline') . ')';
                        }
                        // Preparing rootRec for the mount
-                       $firstHtml .= $this->wrapIcon(IconUtility::getSpriteIcon($icon), $rootLevelFolder);
+                       $firstHtml .= $this->wrapIcon(IconUtility::getSpriteIconForResource($rootLevelFolder, array('mount-root' => TRUE)), $rootLevelFolder);
                        $row = array(
                                'uid' => $folderHashSpecUID,
                                'title' => $rootLevelFolderName,
@@ -389,27 +383,12 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
                        if ($this->makeHTML) {
                                $HTML = $this->PMicon($subFolder, $subFolderCounter, $totalSubFolders, $nextCount, $isOpen);
                                $type = '';
-                               $overlays = array();
 
-                               if ($isLocked) {
-                                       $type = 'readonly';
-                                       $overlays = array('status-overlay-locked' => array());
-                               }
-                               if ($isOpen) {
-                                       $icon = 'apps-filetree-folder-opened';
-                               } else {
-                                       $icon = 'apps-filetree-folder-default';
-                               }
                                $role = $subFolder->getRole();
                                if ($role !== FolderInterface::ROLE_DEFAULT) {
                                        $row['_title'] = '<strong>' . $subFolderName . '</strong>';
                                }
-                               if ($role === FolderInterface::ROLE_TEMPORARY) {
-                                       $icon = 'apps-filetree-folder-temp';
-                               } elseif ($role === FolderInterface::ROLE_RECYCLER) {
-                                       $icon = 'apps-filetree-folder-recycler';
-                               }
-                               $icon = IconUtility::getSpriteIcon($icon, array('title' => $subFolderName), $overlays);
+                               $icon = IconUtility::getSpriteIconForResource($subFolder, array('title' => $subFolderName, 'folder-open' => (bool)$isOpen));
                                $HTML .= $this->wrapIcon($icon, $subFolder);
                        }
                        // Finally, add the row/HTML content to the ->tree array in the reserved key.
index 7f9a989..936a690 100644 (file)
@@ -1574,7 +1574,7 @@ class BackendUtility {
                                        $imgTag = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($fileReferenceObject->getName()) . '" />';
                                } else {
                                        // Icon
-                                       $imgTag = IconUtility::getSpriteIconForFile(strtolower($fileObject->getExtension()), array('title' => $fileObject->getName()));
+                                       $imgTag = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName()));
                                }
                                if ($linkInfoPopup) {
                                        $onClick = 'top.launchView(\'_FILE\',\'' . $fileObject->getUid() . '\',\'' . $backPath . '\'); return false;';
@@ -1618,7 +1618,7 @@ class BackendUtility {
                                                }
                                        } else {
                                                // Gets the icon
-                                               $fileIcon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName()));
+                                               $fileIcon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName()));
                                                if ($linkInfoPopup) {
                                                        $onClick = 'top.launchView(\'_FILE\', \'' . $fileName . '\',\'\',\'' . $backPath . '\'); return false;';
                                                        $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $fileIcon . '</a> ';
index 3578f79..b686222 100644 (file)
@@ -557,21 +557,24 @@ class IconUtility {
         * this is typically wrapped in a <span> tag with corresponding CSS classes that
         * will be responsible for the
         *
-        * There are three ways to use this API:
+        * There are four ways to use this API:
         *
         * 1) for any given TCA record
         *      $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $row);
         *
-        * 2) for any given file
+        * 2) for any given File of Folder object
+        *      $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForResource($fileOrFolderObject);
+        *
+        * 3) for any given file
         *      $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('myimage.png');
         *
-        * 3) for any other icon you know the name
+        * 4) for any other icon you know the name
         *      $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open');
         *
         **********************************************/
        /**
         * This generic method is used throughout the TYPO3 Backend to show icons in any variation which are not
-        * bound to any file type (see getSpriteIconForFile) or database record (see getSpriteIconForRecord)
+        * bound to any resource object (see getSpriteIconForResource) or database record (see getSpriteIconForRecord)
         *
         * Generates a HTML tag with proper CSS classes. The TYPO3 skin has defined these CSS classes
         * already to have a pre-defined background image, and the correct background-position to show
@@ -704,6 +707,82 @@ class IconUtility {
        }
 
        /**
+        * This method is used throughout the TYPO3 Backend to show icons for files and folders
+        *
+        * The method takes care of the translation of file extension to proper icon and for folders
+        * it will return the icon depending on the role of the folder.
+        *
+        * If the given resource is a folder there are some additional options that can be used:
+        *  - mount-root => TRUE (to indicate this is the root of a mount)
+        *  - folder-open => TRUE (to indicate that the folder is opened in the file tree)
+        *
+        * There is a hook in place to manipulate the icon name and overlays.
+        *
+        * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource
+        * @param array $options An associative array with additional options and attributes for the tag. See self::getSpriteIcon()
+        * @param array $overlays An associative array with the icon-name as key, and the options for this overlay as an array again (see the parameter $options again)
+        * @return string
+        * @throws \UnexpectedValueException
+        */
+       static public function getSpriteIconForResource(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, array $options = array(), array $overlays = array()) {
+               // Folder
+               if ($resource instanceof \TYPO3\CMS\Core\Resource\FolderInterface) {
+                       // non browsable storage
+                       if ($resource->getStorage()->isBrowsable() === FALSE && !empty($options['mount-root'])) {
+                               $iconName = 'apps-filetree-folder-locked';
+                       // storage root
+                       } elseif ($resource->getStorage()->getRootLevelFolder()->getIdentifier() === $resource->getIdentifier()) {
+                               $iconName = 'apps-filetree-root';
+                       // user/group mount root
+                       } elseif (!empty($options['mount-root'])) {
+                               $iconName = 'apps-filetree-mount';
+                       } else {
+
+                               // in folder tree view $options['folder-open'] can define a open folder icon
+                               if (!empty($options['folder-open'])) {
+                                       $iconName = 'apps-filetree-folder-opened';
+                               } else {
+                                       $iconName = 'apps-filetree-folder-default';
+                               }
+
+                               $role = $resource->getRole();
+                               if ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_TEMPORARY) {
+                                       $iconName = 'apps-filetree-folder-temp';
+                               } elseif ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_RECYCLER) {
+                                       $iconName = 'apps-filetree-folder-recycler';
+                               }
+
+                               // if locked add overlay
+                               if ($resource instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder) {
+                                       $overlays['status-overlay-locked'] = array();
+                               }
+                       }
+               // File
+               } else {
+                       $iconName = self::mapFileExtensionToSpriteIconName($resource->getExtension());
+
+                       if ($resource instanceof \TYPO3\CMS\Core\Resource\File && $resource->isMissing()) {
+                               $overlays['status-overlay-missing'] = array();
+                       }
+               }
+
+               // Hook: allow some other process to influence the choice of icon and overlays
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'] as $classRef) {
+                               $hookObject = GeneralUtility::getUserObj($classRef);
+                               if (!$hookObject instanceof IconUtilityOverrideResourceIconHookInterface) {
+                                       throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Backend\\Utility\\IconUtilityOverrideResourceIconHookInterface', 1393574895);
+                               }
+                               $hookObject->overrideResourceIcon($resource, $iconName, $options, $overlays);
+                       }
+               }
+
+               unset($options['mount-root']);
+               unset($options['folder-open']);
+               return self::getSpriteIcon($iconName, $options, $overlays);
+       }
+
+       /**
         * this helper functions looks up the column that is used for the type of
         * the chosen TCA table. And then fetches the corresponding class
         * based on the chosen iconsprite class in this TCA
diff --git a/typo3/sysext/backend/Classes/Utility/IconUtilityOverrideResourceIconHookInterface.php b/typo3/sysext/backend/Classes/Utility/IconUtilityOverrideResourceIconHookInterface.php
new file mode 100644 (file)
index 0000000..b1390f0
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+namespace TYPO3\CMS\Backend\Utility;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 Frans Saris <franssaris@gmail.com>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the text file GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Interface for classes which hook into IconUtility::getSpriteIconForResource()
+ */
+interface IconUtilityOverrideResourceIconHookInterface {
+
+       /**
+        * Influence the choice of icon and overlays for a ResourceIcon
+        *
+        * The $iconName, $options and $overlays are passed as references
+        * in order to be modified within the hook
+        *
+        * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource
+        * @param string $iconName
+        * @param array $options
+        * @param array $overlays
+        */
+       public function overrideResourceIcon(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, &$iconName, array &$options, array &$overlays);
+
+}
\ No newline at end of file
index b416a7e..6ae2013 100644 (file)
@@ -80,6 +80,34 @@ class IconUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->mockRecord['bodytext'] = '';
        }
 
+       /**
+        * Create folder object to use as test subject
+        *
+        * @param string $identifier
+        * @return \TYPO3\CMS\Core\Resource\Folder
+        */
+       protected function getTestSubjectFolderObject($identifier) {
+               $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
+               $mockedStorage->expects($this->any())->method('getRootLevelFolder')->will($this->returnValue(
+                       new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, '/', '/')
+               ));
+               return new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, $identifier, $identifier);
+       }
+
+       /**
+        * Create file object to use as test subject
+        *
+        * @param $extension
+        * @return \TYPO3\CMS\Core\Resource\File
+        */
+       protected function getTestSubjectFileObject($extension) {
+               $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
+               $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(array(), $mockedStorage));
+               $mockedFile->expects($this->once())->method('getExtension')->will($this->returnValue($extension));
+
+               return $mockedFile;
+       }
+
        //////////////////////////////////////////
        // Tests concerning imagemake
        //////////////////////////////////////////
@@ -384,4 +412,135 @@ class IconUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                IconUtility::mapRecordOverlayToSpriteIconName('tt_content', array());
        }
 
+       //////////////////////////////////////////////
+       // Tests concerning getSpriteIconForResource
+       //////////////////////////////////////////////
+       /**
+        * Tests the returns of no file
+        *
+        * @test
+        */
+       public function getSpriteIconForResourceWithFileWithoutExtensionTypeReturnsOtherSprite() {
+               $fileObject = $this->getTestSubjectFileObject('');
+               $result = IconUtility::getSpriteIconForResource($fileObject);
+               $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>', $result);
+       }
+
+       /**
+        * Tests the returns of unknown file
+        *
+        * @test
+        */
+       public function getSpriteIconForResourceWithUnknownFileTypeReturnsOtherSprite() {
+               $fileObject = $this->getTestSubjectFileObject('foo');
+               $result = IconUtility::getSpriteIconForResource($fileObject);
+               $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>', $result);
+       }
+
+       /**
+        * Tests the returns of file pdf
+        *
+        * @test
+        */
+       public function getSpriteIconForResourceWithPdfReturnsPdfSprite() {
+               $fileObject = $this->getTestSubjectFileObject('pdf');
+               $result = IconUtility::getSpriteIconForResource($fileObject);
+               $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-pdf t3-icon-pdf">&nbsp;</span>', $result);
+       }
+
+       /**
+        * Tests the returns of file png
+        *
+        * @test
+        */
+       public function getSpriteIconForResourceWithPngFileReturnsPngSprite() {
+               $fileObject = $this->getTestSubjectFileObject('png');
+               $result = IconUtility::getSpriteIconForResource($fileObject);
+               $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>', $result);
+       }
+
+       /**
+        * Tests the returns of file png + option
+        *
+        * @test
+        */
+       public function getSpriteIconForResourceWithPngFileAndOptionsReturnsPngSpriteAndOptions() {
+               $fileObject = $this->getTestSubjectFileObject('png');
+               $result = IconUtility::getSpriteIconForResource($fileObject, array('title' => 'bar'));
+               $this->assertEquals('<span title="bar" class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>', $result);
+       }
+
+       /**
+        * Tests the returns of normal folder
+        *
+        * @test
+        */
+       public function getSpriteIconForResourceWithFolderReturnsFolderSprite() {
+               $folderObject = $this->getTestSubjectFolderObject('/test');
+               $result = IconUtility::getSpriteIconForResource($folderObject);
+               $this->assertEquals('<span class="t3-icon t3-icon-apps t3-icon-apps-filetree t3-icon-filetree-folder-default">&nbsp;</span>', $result);
+       }
+
+       /**
+        * Tests the returns of open folder
+        *
+        * @test
+        */
+       public function getSpriteIconForResourceWithOpenFolderReturnsOpenFolderSprite() {
+               $folderObject = $this->getTestSubjectFolderObject('/test');
+               $result = IconUtility::getSpriteIconForResource($folderObject, array('folder-open' => TRUE));
+               $this->assertEquals('<span class="t3-icon t3-icon-apps t3-icon-apps-filetree t3-icon-filetree-folder-opened">&nbsp;</span>', $result);
+       }
+
+       /**
+        * Tests the returns of root folder
+        *
+        * @test
+        */
+       public function getSpriteIconForResourceWithRootFolderReturnsRootFolderSprite() {
+               $folderObject = $this->getTestSubjectFolderObject('/');
+               $result = IconUtility::getSpriteIconForResource($folderObject);
+               $this->assertEquals('<span class="t3-icon t3-icon-apps t3-icon-apps-filetree t3-icon-filetree-root">&nbsp;</span>', $result);
+       }
+
+       /**
+        * Tests the returns of mount root
+        *
+        * @test
+        */
+       public function getSpriteIconForResourceWithMountRootReturnsMountFolderSprite() {
+               $folderObject = $this->getTestSubjectFolderObject('/mount');
+               $result = IconUtility::getSpriteIconForResource($folderObject, array('mount-root' => TRUE));
+               $this->assertEquals('<span class="t3-icon t3-icon-apps t3-icon-apps-filetree t3-icon-filetree-mount">&nbsp;</span>', $result);
+       }
+
+       /**
+        * Tests whether a overrideResourceIcon hook is called.
+        *
+        * @test
+        */
+       public function isOverrideResourceIconHookCalled() {
+
+               $classReference = uniqid('user_overrideResourceIconHook');
+               $folderObject = $this->getTestSubjectFolderObject('/test');
+               $hookMock = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\IconUtilityOverrideResourceIconHookInterface', array('overrideResourceIcon'), array(), $classReference);
+               $hookMock->expects($this->once())->method('overrideResourceIcon');
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'][$classReference] = $classReference;
+               $GLOBALS['T3_VAR']['getUserObj'][$classReference] = $hookMock;
+               IconUtility::getSpriteIconForResource($folderObject);
+       }
+
+       /**
+        * Tests whether a faulty overrideResourceIcon hook (the hook object cannot be found) is not called.
+        *
+        * @test
+        * @expectedException UnexpectedValueException
+        */
+       public function isFaultyResourceIconHookNotCalled() {
+               $classReference = uniqid('user_overrideResourceIconHook');
+               $folderObject = $this->getTestSubjectFolderObject('/test');
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'][$classReference] = $classReference;
+               $GLOBALS['T3_VAR']['getUserObj'][$classReference] = new \stdClass();
+               IconUtility::getSpriteIconForResource($folderObject);
+       }
 }
index 3b9ab55..c89334d 100644 (file)
@@ -220,21 +220,20 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                        'page_icon' => '',
                        'PASTE' => ''
                );
-               // Makes the code for the foldericon in the top
+               // Makes the code for the folder icon in the top
                if ($folderObject) {
-                       list($_, $icon, $path) = $this->dirData($folderObject);
                        $title = htmlspecialchars($folderObject->getIdentifier());
                        // Start compiling the HTML
                        // @todo: how to fix this? $title = $GLOBALS['SOBE']->basicFF->blindPath($title);
-                       // If this is some subpage under the mount root....
+                       // If this is some subFolder under the mount root....
                        if ($folderObject->getStorage()->isWithinFileMountBoundaries($folderObject)) {
                                // The icon with link
-                               $otherMarkers['PAGE_ICON'] = IconUtility::getSpriteIcon($icon, array('title' => $title));
+                               $otherMarkers['PAGE_ICON'] = IconUtility::getSpriteIconForResource($folderObject, array('title' => $title));
                                // No HTML specialchars here - HTML like <strong> </strong> is allowed
                                $otherMarkers['TITLE'] .= GeneralUtility::removeXSS(GeneralUtility::fixed_lgd_cs($title, -($this->fixedL + 20)));
                        } else {
-                               // This is the root page
-                               $otherMarkers['PAGE_ICON'] = IconUtility::getSpriteIcon('apps-filetree-root');
+                               // This is the root folder
+                               $otherMarkers['PAGE_ICON'] = IconUtility::getSpriteIconForResource($folderObject, array('title' => $title, 'mount-root' => TRUE));
                                $otherMarkers['TITLE'] .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, -($this->fixedL + 20)));
                        }
                        if ($this->clickMenus) {
@@ -465,17 +464,13 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
 
                                // Initialization
                                $this->counter++;
-                               list($_, $icon, $path) = $this->dirData($folderObject);
-                               // The icon with link
 
-                               if (!$isLocked) {
-                                       $theIcon = IconUtility::getSpriteIcon($icon, array('title' => $folderName));
-                                       if (!$this->clickMenus) {
-                                               $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
-                                       }
-                               } else {
-                                       $theIcon = IconUtility::getSpriteIcon($icon, array('title' => $folderName), array('status-overlay-locked' => array()));
+                               // The icon with link
+                               $theIcon = IconUtility::getSpriteIconForResource($folderObject, array('title' => $folderName));
+                               if (!$isLocked && !$this->clickMenus) {
+                                       $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
                                }
+
                                // Preparing and getting the data-array
                                $theData = array();
                                if ($isLocked) {
@@ -583,9 +578,11 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
         *
         * @param \TYPO3\CMS\Core\Resource\Folder $folderObject File information array
         * @return array (title, icon, path)
-        * @todo Define visibility
+        * @deprecated since 6.2 - will be removed two versions later without replacement
         */
        public function dirData(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
+               GeneralUtility::logDeprecatedFunction();
+
                $title = htmlspecialchars($folderObject->getName());
                $icon = 'apps-filetree-folder-default';
                $role = $folderObject->getRole();
@@ -628,7 +625,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                $ext = $fileObject->getExtension();
                                $fileName = trim($fileObject->getName());
                                // The icon with link
-                               $theIcon = IconUtility::getSpriteIconForFile($ext, array('title' => $fileName));
+                               $theIcon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileName));
                                if ($this->clickMenus) {
                                        $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
                                }
index 98e3682..618a81a 100644 (file)
@@ -1677,7 +1677,7 @@ class ElementBrowser {
                        }
                        // Create header element; The folder from which files are listed.
                        $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
-                       $folderIcon = IconUtility::getSpriteIconForFile('folder');
+                       $folderIcon = IconUtility::getSpriteIconForResource($folder);
                        $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen));
                        $picon = '<a href="#" onclick="return link_folder(\'file:' . $folder->getCombinedIdentifier() . '\');">'
                                . $folderIcon . '</a>';
@@ -1714,7 +1714,7 @@ class ElementBrowser {
                                        $fileExtension = $fileOrFolderObject->getExtension();
                                        // Get size and icon:
                                        $size = ' (' . GeneralUtility::formatSize($fileOrFolderObject->getSize()) . 'bytes)';
-                                       $icon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileOrFolderObject->getName() . $size));
+                                       $icon = IconUtility::getSpriteIconForResource($fileOrFolderObject, array('title' => $fileOrFolderObject->getName() . $size));
                                        $itemUid = 'file:' . $fileIdentifier;
                                }
                                // If the listed file turns out to be the CURRENT file, then show blinking arrow:
@@ -1781,7 +1781,7 @@ class ElementBrowser {
                $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
                // Create the header of current folder:
                if ($folder) {
-                       $folderIcon = IconUtility::getSpriteIconForFile('folder');
+                       $folderIcon = IconUtility::getSpriteIconForResource($folder);
                        $lines[] = '<tr class="t3-row-header">
                                <td colspan="4">' . $folderIcon
                                . htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
@@ -1819,7 +1819,7 @@ class ElementBrowser {
                        }
                        // Create file icon:
                        $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
-                       $icon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
+                       $icon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName() . $size));
                        // Create links for adding the file:
                        $filesIndex = count($this->elements);
                        $this->elements['file_' . $filesIndex] = array(
@@ -2049,7 +2049,7 @@ class ElementBrowser {
                                $imgInfo = @getimagesize($fileObject->getForLocalProcessing(FALSE));
                                $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
                                $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
-                               $filenameAndIcon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
+                               $filenameAndIcon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName() . $size));
                                if (GeneralUtility::_GP('noLimit')) {
                                        $maxW = 10000;
                                        $maxH = 10000;