Skip to content

Commit

Permalink
[TASK] Get icon with PathUtility instead of ResourceFactory (#653)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikita Hovratov <[email protected]>
  • Loading branch information
jakowidhalm and nhovratov authored Nov 22, 2024
1 parent 16a2c36 commit c45a82d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions Classes/Imaging/PreviewIconResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,20 @@

namespace MASK\Mask\Imaging;

use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;

class PreviewIconResolver
{
/**
* @var array<string, string>
*/
protected array $maskExtensionConfiguration;
protected ResourceFactory $resourceFactory;

public function __construct(
array $maskExtensionConfiguration,
ResourceFactory $resourceFactory
array $maskExtensionConfiguration
) {
$this->maskExtensionConfiguration = $maskExtensionConfiguration;
$this->resourceFactory = $resourceFactory;
}

/**
Expand All @@ -55,14 +50,13 @@ public function getPreviewIconPath(string $key): string
$fileExtensions = ['png', 'svg'];
$previewPath = rtrim($this->maskExtensionConfiguration['preview'], '/');
foreach ($fileExtensions as $fileExtension) {
try {
$icon = $this->resourceFactory->retrieveFileOrFolderObject($previewPath . '/' . $key . '.' . $fileExtension);
} catch (\InvalidArgumentException|FolderDoesNotExistException|ResourceDoesNotExistException $e) {
$extPathToIcon = $previewPath . '/' . $key . '.' . $fileExtension;
$absolutePathToIcon = GeneralUtility::getFileAbsFileName($extPathToIcon);
if ($absolutePathToIcon === '' || !file_exists($absolutePathToIcon)) {
continue;
}
if ($icon instanceof File && $icon->exists()) {
return '/' . ltrim($icon->getPublicUrl(), '/');
}
$resource = PathUtility::getPublicResourceWebPath($extPathToIcon);
return '/' . ltrim($resource, '/');
}

return '';
Expand Down

0 comments on commit c45a82d

Please sign in to comment.