diff --git a/Classes/Command/ContentElementCommand.php b/Classes/Command/ContentElementCommand.php index 544fcb2..f0488f8 100644 --- a/Classes/Command/ContentElementCommand.php +++ b/Classes/Command/ContentElementCommand.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. @@ -75,7 +75,7 @@ class ContentElementCommand extends Command ->executeQuery() ->fetchAllAssociative(); - (new Table($output)) + new Table($output) ->setHeaderTitle('Content in tree ' . $pageId) ->setHeaders(array_keys($result[0])) ->setRows($result) @@ -141,7 +141,7 @@ class ContentElementCommand extends Command * that you want to use as a WHERE fragment is not prefixed. * * @param string $constraint The where part fragment with a possible leading AND / OR operator - * @return string The modified where part without leading operator + * @return string The modified where part without a leading operator */ public function stripLogicalOperatorPrefix(string $constraint): string { diff --git a/Classes/Configuration/AdditionalConfiguration.php b/Classes/Configuration/AdditionalConfiguration.php index 4cb77d9..2f58cd0 100644 --- a/Classes/Configuration/AdditionalConfiguration.php +++ b/Classes/Configuration/AdditionalConfiguration.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. */ namespace Evoweb\EwBase\Configuration; diff --git a/Classes/DataProcessing/DatabaseQueryProcessor.php b/Classes/DataProcessing/DatabaseQueryProcessor.php index 7f6d5b9..82baf11 100644 --- a/Classes/DataProcessing/DatabaseQueryProcessor.php +++ b/Classes/DataProcessing/DatabaseQueryProcessor.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/EventListener/CssMerger.php b/Classes/EventListener/CssMerger.php index c171f04..d0bd8ab 100644 --- a/Classes/EventListener/CssMerger.php +++ b/Classes/EventListener/CssMerger.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/EventListener/JsMerger.php b/Classes/EventListener/JsMerger.php index 8fd6092..6792142 100644 --- a/Classes/EventListener/JsMerger.php +++ b/Classes/EventListener/JsMerger.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/Form/Element/PickColorFromImage.php b/Classes/Form/Element/PickColorFromImage.php index 38eb3f8..1628d40 100644 --- a/Classes/Form/Element/PickColorFromImage.php +++ b/Classes/Form/Element/PickColorFromImage.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. @@ -214,7 +214,7 @@ class PickColorFromImage extends AbstractFormElement { $defaultConfig = self::$defaultConfig; - // If ratios are set do not add default options + // If ratios are set, do not add default options if (isset($baseConfiguration['cropVariants'])) { unset($defaultConfig['cropVariants']); } @@ -233,7 +233,7 @@ class PickColorFromImage extends AbstractFormElement }); // Aspect ratios may not contain a "." character, see Ratio::__construct() - // To match them again properly, same replacement is required here. + // To match them again properly, the same replacement is required here. $preparedAllowedAspectRatios = []; foreach ($cropVariant['allowedAspectRatios'] as $aspectRatio => $aspectRatioDefinition) { $preparedAllowedAspectRatios[Ratio::prepareAspectRatioId($aspectRatio)] = $aspectRatioDefinition; @@ -259,7 +259,7 @@ class PickColorFromImage extends AbstractFormElement $config['cropVariants'] = $cropVariants; - // By default we allow all image extensions that can be handled by the GFX functionality + // By default, we allow all image extensions that can be handled by the GFX functionality $config['allowedExtensions'] ??= $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']; return $config; } diff --git a/Classes/Services/QueryBuilderHelper.php b/Classes/Services/QueryBuilderHelper.php index aa385fa..d3a2111 100644 --- a/Classes/Services/QueryBuilderHelper.php +++ b/Classes/Services/QueryBuilderHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. @@ -20,7 +20,7 @@ use Doctrine\DBAL\ParameterType; use TYPO3\CMS\Core\Database\Query\QueryBuilder; /** - * Utility class that parses sql statements with regard to types and parameters. + * Utility class that parses SQL statements with regard to types and parameters. */ class QueryBuilderHelper { @@ -53,7 +53,7 @@ class QueryBuilderHelper } /** - * Gets an array of the placeholders in a sql statements as keys and their positions in the query string. + * Gets an array of the placeholders in a SQL statement as keys and their positions in the query string. * * For a statement with positional parameters, returns a zero-indexed list of placeholder position. * For a statement with named parameters, returns a map of placeholder positions to their parameter names. @@ -127,7 +127,7 @@ class QueryBuilderHelper } /** - * For a positional query this method can rewrite the sql statement with regard to array parameters. + * For a positional query this method can rewrite the SQL statement with regard to array parameters. * * @throws \Exception */ @@ -160,7 +160,7 @@ class QueryBuilderHelper $arrayPositions[$name] = false; } - // parameter are positional and no array parameter given + // parameters are positional and no array parameter given if ($isPositional && !$arrayPositions) { return [$query, $params, $types]; } @@ -210,7 +210,7 @@ class QueryBuilderHelper $expandStr = $count ? implode(', ', array_fill(0, $count, '?')) : 'NULL'; $query = substr($query, 0, $needlePos) . $expandStr . substr($query, $needlePos + 1); - $paramOffset += $count - 1; // Grows larger by number of parameters minus the replaced needle. + $paramOffset += $count - 1; // Grows larger by the number of parameters minus the replaced needle. $queryOffset += strlen($expandStr) - 1; } diff --git a/Classes/Services/Tailwindcss4Merger.php b/Classes/Services/Tailwindcss4Merger.php index 619cb64..27502cf 100644 --- a/Classes/Services/Tailwindcss4Merger.php +++ b/Classes/Services/Tailwindcss4Merger.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/User/AssetPath.php b/Classes/User/AssetPath.php index 8232df3..6cf53e6 100644 --- a/Classes/User/AssetPath.php +++ b/Classes/User/AssetPath.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. @@ -15,6 +15,9 @@ declare(strict_types=1); namespace Evoweb\EwBase\User; +use TYPO3\CMS\Core\SystemResource\Exception\CanNotResolvePublicResourceException; +use TYPO3\CMS\Core\SystemResource\Exception\CanNotResolveSystemResourceException; +use TYPO3\CMS\Core\SystemResource\Publishing\UriGenerationOptions; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\PathUtility; @@ -27,10 +30,18 @@ use TYPO3\CMS\Core\Utility\PathUtility; */ class AssetPath { + /** + * @throws CanNotResolvePublicResourceException + * @throws CanNotResolveSystemResourceException + */ public function getAbsolutePublicPath(string $content, array $conf): string { return $content . GeneralUtility::getIndpEnv('TYPO3_SITE_URL') - . ltrim(PathUtility::getPublicResourceWebPath($conf['file']), '/'); + . ltrim((string)PathUtility::getSystemResourceUri( + $conf['file'], + null, + new UriGenerationOptions(cacheBusting: false) + ), '/'); } } diff --git a/Classes/ViewHelpers/Array/AddViewHelper.php b/Classes/ViewHelpers/Array/AddViewHelper.php index 06357e8..4d50493 100644 --- a/Classes/ViewHelpers/Array/AddViewHelper.php +++ b/Classes/ViewHelpers/Array/AddViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/Array/ExplodeViewHelper.php b/Classes/ViewHelpers/Array/ExplodeViewHelper.php index 0d04347..397132e 100755 --- a/Classes/ViewHelpers/Array/ExplodeViewHelper.php +++ b/Classes/ViewHelpers/Array/ExplodeViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/Be/ThumbnailViewHelper.php b/Classes/ViewHelpers/Be/ThumbnailViewHelper.php index bcdeb65..8d318f2 100644 --- a/Classes/ViewHelpers/Be/ThumbnailViewHelper.php +++ b/Classes/ViewHelpers/Be/ThumbnailViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. @@ -16,13 +16,22 @@ declare(strict_types=1); namespace Evoweb\EwBase\ViewHelpers\Be; use Psr\Http\Message\ServerRequestInterface; +use Psr\Log\LoggerInterface; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; +use TYPO3\CMS\Core\Database\RelationHandler; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Imaging\IconSize; use TYPO3\CMS\Core\Localization\LanguageService; +use TYPO3\CMS\Core\Log\LogManager; +use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException; +use TYPO3\CMS\Core\Resource\FileReference; use TYPO3\CMS\Core\Resource\ProcessedFile; +use TYPO3\CMS\Core\Resource\ResourceFactory; +use TYPO3\CMS\Core\Schema\Field\FileFieldType; +use TYPO3\CMS\Core\Schema\TcaSchema; +use TYPO3\CMS\Core\Schema\TcaSchemaFactory; use TYPO3\CMS\Core\Type\Bitmask\Permission; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; @@ -48,7 +57,7 @@ class ThumbnailViewHelper extends AbstractViewHelper $field = $this->arguments['fieldName']; $row = $this->arguments['row']; - $fileReferences = BackendUtility::resolveFileReferences($table, $field, $row); + $fileReferences = $this->resolveFileReferences($table, $field, $row); $fileObject = is_array($fileReferences) ? current($fileReferences)->getOriginalFile() : null; if ($fileObject && $fileObject->isMissing()) { @@ -74,6 +83,65 @@ class ThumbnailViewHelper extends AbstractViewHelper return $this->linkEditContent('', $row ); } + public function resolveFileReferences( + string $tableName, + string $fieldName, + array $element, + ?int $workspaceId = null + ): ?array { + if (!($schema = self::getTcaSchema($tableName))?->hasField($fieldName)) { + return null; + } + $field = $schema->getField($fieldName); + if ($field instanceof FileFieldType === false) { + return null; + } + + $fileReferences = []; + $relationHandler = GeneralUtility::makeInstance(RelationHandler::class); + if ($workspaceId !== null) { + $relationHandler->setWorkspaceId($workspaceId); + } + $relationHandler->initializeForField( + $tableName, + $field->getConfiguration(), + $element, + $element[$fieldName], + ); + $relationHandler->processDeletePlaceholder(); + $referenceUids = $relationHandler->tableArray[$field->getConfiguration()['foreign_table']] ?? []; + + foreach ($referenceUids as $referenceUid) { + try { + $fileReference = GeneralUtility::makeInstance(ResourceFactory::class)->getFileReferenceObject( + $referenceUid, + [], + $workspaceId === 0 + ); + $fileReferences[$fileReference->getUid()] = $fileReference; + } catch (FileDoesNotExistException $e) { + /** + * We just catch the exception here + * Reasoning: There is nothing an editor or even admin could do + */ + } catch (\InvalidArgumentException $e) { + /** + * The storage does not exist anymore + * Log the exception message for admins as they maybe can restore the storage + */ + // @extensionScannerIgnoreLine + self::getLogger()->error($e->getMessage(), [ + 'table' => $tableName, + 'fieldName' => $fieldName, + 'referenceUid' => $referenceUid, + 'exception' => $e, + ]); + } + } + + return $fileReferences; + } + protected function linkEditContent(string $linkText, $row): string { if (empty($linkText)) { @@ -84,10 +152,8 @@ class ThumbnailViewHelper extends AbstractViewHelper if ( $backendUser->check('tables_modify', 'tt_content') && $backendUser->recordEditAccessInternals('tt_content', $row) - && ( - new Permission( - $backendUser->calcPerms(BackendUtility::getRecord('pages', $row['pid']) ?? []) - ) + && new Permission( + $backendUser->calcPerms(BackendUtility::getRecord('pages', $row['pid']) ?? []) )->editContentPermissionIsGranted() ) { $urlParameters = [ @@ -112,6 +178,17 @@ class ThumbnailViewHelper extends AbstractViewHelper return $linkText; } + protected static function getLogger(): LoggerInterface + { + return GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); + } + + protected static function getTcaSchema(string $tableName): ?TcaSchema + { + $schemaFactory = GeneralUtility::makeInstance(TcaSchemaFactory::class); + return $schemaFactory->has($tableName) ? $schemaFactory->get($tableName) : null; + } + protected function getBackendUser(): BackendUserAuthentication { return $GLOBALS['BE_USER']; diff --git a/Classes/ViewHelpers/Condition/InArrayViewHelper.php b/Classes/ViewHelpers/Condition/InArrayViewHelper.php index 36b47a2..48b245e 100644 --- a/Classes/ViewHelpers/Condition/InArrayViewHelper.php +++ b/Classes/ViewHelpers/Condition/InArrayViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/Condition/StringContainsViewHelper.php b/Classes/ViewHelpers/Condition/StringContainsViewHelper.php index 7b28cc6..5999286 100644 --- a/Classes/ViewHelpers/Condition/StringContainsViewHelper.php +++ b/Classes/ViewHelpers/Condition/StringContainsViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/Context/DevelopmentViewHelper.php b/Classes/ViewHelpers/Context/DevelopmentViewHelper.php index fe4a5b2..aaf94e6 100644 --- a/Classes/ViewHelpers/Context/DevelopmentViewHelper.php +++ b/Classes/ViewHelpers/Context/DevelopmentViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/Context/ProductionViewHelper.php b/Classes/ViewHelpers/Context/ProductionViewHelper.php index e57fc31..f0e7ba7 100644 --- a/Classes/ViewHelpers/Context/ProductionViewHelper.php +++ b/Classes/ViewHelpers/Context/ProductionViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/Context/StagingViewHelper.php b/Classes/ViewHelpers/Context/StagingViewHelper.php index bbbae08..5e1a527 100644 --- a/Classes/ViewHelpers/Context/StagingViewHelper.php +++ b/Classes/ViewHelpers/Context/StagingViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/FixFlexformForExtbaseViewHelper.php b/Classes/ViewHelpers/FixFlexformForExtbaseViewHelper.php index f9aa34d..2b1d4e5 100644 --- a/Classes/ViewHelpers/FixFlexformForExtbaseViewHelper.php +++ b/Classes/ViewHelpers/FixFlexformForExtbaseViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/FlexFormViewHelper.php b/Classes/ViewHelpers/FlexFormViewHelper.php index ea793b0..f497b36 100644 --- a/Classes/ViewHelpers/FlexFormViewHelper.php +++ b/Classes/ViewHelpers/FlexFormViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/PublicPathViewHelper.php b/Classes/ViewHelpers/PublicPathViewHelper.php index f9c1329..1f5939b 100644 --- a/Classes/ViewHelpers/PublicPathViewHelper.php +++ b/Classes/ViewHelpers/PublicPathViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. @@ -16,6 +16,9 @@ declare(strict_types=1); namespace Evoweb\EwBase\ViewHelpers; use TYPO3\CMS\Core\Resource\Exception\InvalidFileException; +use TYPO3\CMS\Core\SystemResource\Exception\CanNotResolvePublicResourceException; +use TYPO3\CMS\Core\SystemResource\Exception\CanNotResolveSystemResourceException; +use TYPO3\CMS\Core\SystemResource\Publishing\UriGenerationOptions; use TYPO3\CMS\Core\Utility\PathUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; @@ -25,9 +28,6 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; * * .... * - * - * fixed flexform data for extbase controller - * * * @api */ @@ -45,11 +45,12 @@ class PublicPathViewHelper extends AbstractViewHelper } /** - * @throws InvalidFileException + * @throws CanNotResolvePublicResourceException + * @throws CanNotResolveSystemResourceException */ - public function renderStatic(): string + public function render(): string { $path = (string)$this->arguments['path']; - return PathUtility::getPublicResourceWebPath($path); + return (string)PathUtility::getSystemResourceUri($path, null, new UriGenerationOptions(cacheBusting: false)); } } diff --git a/Classes/ViewHelpers/ReplaceViewHelper.php b/Classes/ViewHelpers/ReplaceViewHelper.php index a9fe781..5f79248 100644 --- a/Classes/ViewHelpers/ReplaceViewHelper.php +++ b/Classes/ViewHelpers/ReplaceViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/SvgViewHelper.php b/Classes/ViewHelpers/SvgViewHelper.php index 6dc418f..7c5118f 100644 --- a/Classes/ViewHelpers/SvgViewHelper.php +++ b/Classes/ViewHelpers/SvgViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/Classes/ViewHelpers/TrimViewHelper.php b/Classes/ViewHelpers/TrimViewHelper.php index 5d1db02..e43c43c 100644 --- a/Classes/ViewHelpers/TrimViewHelper.php +++ b/Classes/ViewHelpers/TrimViewHelper.php @@ -7,7 +7,7 @@ declare(strict_types=1); * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. + * of the License or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. diff --git a/composer.json b/composer.json index 9c1df1f..c775a01 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "evoweb/ew-base", "type": "typo3-cms-extension", + "description": "Site base", "autoload": { "psr-4": { "Evoweb\\EwBase\\": "Classes/"