Ejemplo n.º 1
0
 /**
  * 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 ResourceInterface $resource
  * @param string $size "large" "small" or "default", see the constants of the Icon class
  * @param string $overlayIdentifier
  * @param array $options An associative array with additional options.
  * @return Icon
  */
 public function getIconForResource(ResourceInterface $resource, $size = Icon::SIZE_DEFAULT, $overlayIdentifier = null, array $options = array())
 {
     $iconIdentifier = null;
     // Folder
     if ($resource instanceof FolderInterface) {
         // non browsable storage
         if ($resource->getStorage()->isBrowsable() === false && !empty($options['mount-root'])) {
             $iconIdentifier = 'apps-filetree-folder-locked';
         } else {
             // storage root
             if ($resource->getStorage()->getRootLevelFolder()->getIdentifier() === $resource->getIdentifier()) {
                 $iconIdentifier = 'apps-filetree-root';
             }
             $role = is_callable([$resource, 'getRole']) ? $resource->getRole() : '';
             // user/group mount root
             if (!empty($options['mount-root'])) {
                 $iconIdentifier = 'apps-filetree-mount';
                 if ($role === FolderInterface::ROLE_READONLY_MOUNT) {
                     $overlayIdentifier = 'overlay-locked';
                 } elseif ($role === FolderInterface::ROLE_USER_MOUNT) {
                     $overlayIdentifier = 'overlay-restricted';
                 }
             }
             if ($iconIdentifier === null) {
                 // in folder tree view $options['folder-open'] can define an open folder icon
                 if (!empty($options['folder-open'])) {
                     $iconIdentifier = 'apps-filetree-folder-opened';
                 } else {
                     $iconIdentifier = 'apps-filetree-folder-default';
                 }
                 if ($role === FolderInterface::ROLE_TEMPORARY) {
                     $iconIdentifier = 'apps-filetree-folder-temp';
                 } elseif ($role === FolderInterface::ROLE_RECYCLER) {
                     $iconIdentifier = 'apps-filetree-folder-recycler';
                 }
             }
             // if locked add overlay
             if ($resource instanceof InaccessibleFolder || !$resource->getStorage()->isBrowsable() || !$resource->getStorage()->checkFolderActionPermission('add', $resource)) {
                 $overlayIdentifier = 'overlay-locked';
             }
         }
         // File
     } elseif ($resource instanceof File) {
         $mimeTypeIcon = $this->iconRegistry->getIconIdentifierForMimeType($resource->getMimeType());
         // Check if we find a exact matching mime type
         if ($mimeTypeIcon !== null) {
             $iconIdentifier = $mimeTypeIcon;
         } else {
             $fileExtensionIcon = $this->iconRegistry->getIconIdentifierForFileExtension($resource->getExtension());
             if ($fileExtensionIcon !== 'mimetypes-other-other') {
                 // Fallback 1: icon by file extension
                 $iconIdentifier = $fileExtensionIcon;
             } else {
                 // Fallback 2: icon by mime type with subtype replaced by *
                 $mimeTypeParts = explode('/', $resource->getMimeType());
                 $mimeTypeIcon = $this->iconRegistry->getIconIdentifierForMimeType($mimeTypeParts[0] . '/*');
                 if ($mimeTypeIcon !== null) {
                     $iconIdentifier = $mimeTypeIcon;
                 } else {
                     // Fallback 3: use 'mimetypes-other-other'
                     $iconIdentifier = $fileExtensionIcon;
                 }
             }
         }
         if ($resource->isMissing()) {
             $overlayIdentifier = 'overlay-missing';
         }
     }
     unset($options['mount-root']);
     unset($options['folder-open']);
     list($iconIdentifier, $overlayIdentifier) = $this->emitBuildIconForResourceSignal($resource, $size, $options, $iconIdentifier, $overlayIdentifier);
     return $this->getIcon($iconIdentifier, $size, $overlayIdentifier);
 }
Ejemplo n.º 2
0
 /**
  * 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
  */
 public static function getSpriteIconForResource(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, array $options = array(), array $overlays = array())
 {
     // Folder
     if ($resource instanceof \TYPO3\CMS\Core\Resource\FolderInterface) {
         $iconName = NULL;
         $role = $resource->getRole();
         // non browsable storage
         if ($resource->getStorage()->isBrowsable() === FALSE && !empty($options['mount-root'])) {
             $iconName = 'apps-filetree-folder-locked';
         } else {
             // storage root
             if ($resource->getStorage()->getRootLevelFolder()->getIdentifier() === $resource->getIdentifier()) {
                 $iconName = 'apps-filetree-root';
             }
             // user/group mount root
             if (!empty($options['mount-root'])) {
                 $iconName = 'apps-filetree-mount';
                 if ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_READONLY_MOUNT) {
                     $overlays['status-overlay-locked'] = array();
                 } elseif ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_USER_MOUNT) {
                     $overlays['status-overlay-access-restricted'] = array();
                 }
             }
             if ($iconName === NULL) {
                 // 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';
                 }
                 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 || !$resource->getStorage()->isBrowsable() || !$resource->getStorage()->checkFolderActionPermission('add', $resource)) {
                 $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);
 }
Ejemplo n.º 3
0
 /**
  * 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 ResourceInterface $resource
  * @param string $size "large" "small" or "default", see the constants of the Icon class
  * @param string $overlayIdentifier
  * @param array $options An associative array with additional options.
  * @return Icon
  */
 public function getIconForResource(ResourceInterface $resource, $size = Icon::SIZE_DEFAULT, $overlayIdentifier = null, array $options = array())
 {
     $iconIdentifier = null;
     // Folder
     if ($resource instanceof FolderInterface) {
         // non browsable storage
         if ($resource->getStorage()->isBrowsable() === false && !empty($options['mount-root'])) {
             $iconIdentifier = 'apps-filetree-folder-locked';
         } else {
             // storage root
             if ($resource->getStorage()->getRootLevelFolder()->getIdentifier() === $resource->getIdentifier()) {
                 $iconIdentifier = 'apps-filetree-root';
             }
             $role = is_callable([$resource, 'getRole']) ? $resource->getRole() : '';
             // user/group mount root
             if (!empty($options['mount-root'])) {
                 $iconIdentifier = 'apps-filetree-mount';
                 if ($role === FolderInterface::ROLE_READONLY_MOUNT) {
                     $overlayIdentifier = 'overlay-locked';
                 } elseif ($role === FolderInterface::ROLE_USER_MOUNT) {
                     $overlayIdentifier = 'overlay-restricted';
                 }
             }
             if ($iconIdentifier === null) {
                 // in folder tree view $options['folder-open'] can define an open folder icon
                 if (!empty($options['folder-open'])) {
                     $iconIdentifier = 'apps-filetree-folder-opened';
                 } else {
                     $iconIdentifier = 'apps-filetree-folder-default';
                 }
                 if ($role === FolderInterface::ROLE_TEMPORARY) {
                     $iconIdentifier = 'apps-filetree-folder-temp';
                 } elseif ($role === FolderInterface::ROLE_RECYCLER) {
                     $iconIdentifier = 'apps-filetree-folder-recycler';
                 }
             }
             // if locked add overlay
             if ($resource instanceof InaccessibleFolder || !$resource->getStorage()->isBrowsable() || !$resource->getStorage()->checkFolderActionPermission('add', $resource)) {
                 $overlayIdentifier = 'overlay-locked';
             }
         }
         // File
     } else {
         if ($resource instanceof File && $resource->isMissing()) {
             $overlayIdentifier = 'overlay-missing';
         }
         $iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
         $iconIdentifier = $iconRegistry->getIconIdentifierForFileExtension($resource->getExtension());
     }
     unset($options['mount-root']);
     unset($options['folder-open']);
     list($iconIdentifier, $overlayIdentifier) = $this->emitBuildIconForResourceSignal($resource, $size, $options, $iconIdentifier, $overlayIdentifier);
     return $this->getIcon($iconIdentifier, $size, $overlayIdentifier);
 }