/** * Registers new icons * * @param $identifier * @param $iconFile */ private function registerIcon($identifier, $iconFile) { $fileInfo = pathinfo($iconFile); if ($fileInfo['extension'] == 'svg') { if (!$this->iconRegistry->isRegistered($identifier)) { $this->iconRegistry->registerIcon($identifier, \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class, array('source' => $iconFile)); } } else { if (!$this->iconRegistry->isRegistered($identifier)) { $this->iconRegistry->registerIcon($identifier, \TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class, array('source' => $iconFile)); } } }
/** * @param string $identifier * @param string $size "large", "small" or "default", see the constants of the Icon class * @param string $overlayIdentifier * @param IconState $state * @return Icon */ public function getIcon($identifier, $size = Icon::SIZE_DEFAULT, $overlayIdentifier = null, IconState $state = null) { if ($this->iconRegistry->isDeprecated($identifier)) { $deprecationSettings = $this->iconRegistry->getDeprecationSettings($identifier); GeneralUtility::deprecationLog(sprintf($deprecationSettings['message'], $identifier)); if (!empty($deprecationSettings['replacement'])) { $identifier = $deprecationSettings['replacement']; } } if (!$this->iconRegistry->isRegistered($identifier)) { $identifier = $this->iconRegistry->getDefaultIconIdentifier(); } $iconConfiguration = $this->iconRegistry->getIconConfigurationByIdentifier($identifier); $iconConfiguration['state'] = $state; $icon = $this->createIcon($identifier, $size, $overlayIdentifier, $iconConfiguration); /** @var IconProviderInterface $iconProvider */ $iconProvider = GeneralUtility::makeInstance($iconConfiguration['provider']); $iconProvider->prepareIconMarkup($icon, $iconConfiguration['options']); return $icon; }
/** * @test */ public function registerFileExtensionOverwriteAnExistingIcon() { $this->subject->registerFileExtension('jpg', 'xyz'); $result = $this->subject->getIconIdentifierForFileExtension('jpg'); $this->assertEquals('xyz', $result); }
/** * 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); }
/** * @test * @param $deprecationSettings * @param $expected * @dataProvider getIconReturnsReplacementIconWhenDeprecatedDataProvider */ public function getIconReturnsReplacementIconWhenDeprecated($deprecationSettings, $expected) { $this->iconRegistryMock->isDeprecated($this->registeredIconIdentifier)->willReturn(true); $this->iconRegistryMock->getDeprecationSettings($this->registeredIconIdentifier)->willReturn($deprecationSettings); $this->assertContains($expected, $this->subject->getIcon($this->registeredIconIdentifier, Icon::SIZE_SMALL)->render()); }
/** * @test */ public function getIconIdentifierForMimeTypeWithUnknowMimeTypeReturnNull() { $result = $this->subject->getIconIdentifierForMimeType('bar/foo'); $this->assertEquals(null, $result); }
/** * @test */ public function getIconReturnsCorrectMarkupIfIconIsRegisteredAsSpinningIcon() { $this->iconRegistryMock->getIconConfigurationByIdentifier($this->registeredSpinningIconIdentifier)->willReturn(['provider' => FontawesomeIconProvider::class, 'options' => array('name' => 'times-circle', 'additionalClasses' => 'fa-fw', 'spinning' => true)]); $this->assertContains('<span class="t3js-icon icon icon-size-default icon-state-default icon-' . $this->registeredSpinningIconIdentifier . ' icon-spin" data-identifier="spinning-icon">', $this->subject->getIcon($this->registeredSpinningIconIdentifier)->render()); }