From 3c7673832c3b112cc71824d3dadb2e8993cd130c Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Wed, 15 Dec 2021 19:07:29 +0100 Subject: [PATCH] [TASK] Avoid extending ImageViewHelper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To prepare making all view helpers final as anticipated with #95298, ext:backend ThumbnailViewhelper must no longer extend ext:fluid ImageViewHelper. The patch is a simple transition, we may later have a look at the ThumbnailViewHelper again, since probably some of the possible arguments are not needed for thumbnails. Resolves: #96362 Related: #95298 Releases: main Change-Id: Ibf0f3ac108ab1849454769a947061a4604eb9fbf Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72666 Tested-by: core-ci <typo3@b13.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Benni Mack <benni@typo3.org> Tested-by: Oliver Bartsch <bo@cedev.de> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Benni Mack <benni@typo3.org> Reviewed-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../ViewHelpers/ThumbnailViewHelper.php | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php index a68d3533d915..bf44632c02d5 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php @@ -18,7 +18,9 @@ namespace TYPO3\CMS\Backend\ViewHelpers; use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection; use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException; use TYPO3\CMS\Core\Resource\ProcessedFile; -use TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Service\ImageService; +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Exception; /** @@ -57,8 +59,20 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Exception; * alt="alt set in image record" * title="title set in image record"/> */ -class ThumbnailViewHelper extends ImageViewHelper +class ThumbnailViewHelper extends AbstractTagBasedViewHelper { + /** + * @var string + */ + protected $tagName = 'img'; + + protected ImageService $imageService; + + public function __construct() + { + parent::__construct(); + $this->imageService = GeneralUtility::makeInstance(ImageService::class); + } /** * Initialize arguments. @@ -66,15 +80,33 @@ class ThumbnailViewHelper extends ImageViewHelper public function initializeArguments() { parent::initializeArguments(); + $this->registerUniversalTagAttributes(); + $this->registerTagAttribute('alt', 'string', 'Specifies an alternate text for an image', false); + $this->registerTagAttribute('ismap', 'string', 'Specifies an image as a server-side image-map. Rarely used. Look at usemap instead', false); + $this->registerTagAttribute('longdesc', 'string', 'Specifies the URL to a document that contains a long description of an image', false); + $this->registerTagAttribute('usemap', 'string', 'Specifies an image as a client-side image-map', false); + $this->registerTagAttribute('loading', 'string', 'Native lazy-loading for images property. Can be "lazy", "eager" or "auto"', false); + $this->registerTagAttribute('decoding', 'string', 'Provides an image decoding hint to the browser. Can be "sync", "async" or "auto"', false); + + // @todo: Probably not all of these are needed for thumbnails. That's a left over from ImageViewHelper + $this->registerArgument('src', 'string', 'a path to a file, a combined FAL identifier or an uid (int). If $treatIdAsReference is set, the integer is considered the uid of the sys_file_reference record. If you already got a FAL object, consider using the $image parameter instead', false, ''); + $this->registerArgument('treatIdAsReference', 'bool', 'given src argument is a sys_file_reference record', false, false); + $this->registerArgument('image', 'object', 'a FAL object (\\TYPO3\\CMS\\Core\\Resource\\File or \\TYPO3\\CMS\\Core\\Resource\\FileReference)'); + $this->registerArgument('crop', 'string|bool', 'overrule cropping of image (setting to FALSE disables the cropping set in FileReference)'); + $this->registerArgument('cropVariant', 'string', 'select a cropping variant, in case multiple croppings have been specified or stored in FileReference', false, 'default'); + $this->registerArgument('fileExtension', 'string', 'Custom file extension to use'); + + $this->registerArgument('width', 'string', 'width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.'); + $this->registerArgument('height', 'string', 'height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.'); + $this->registerArgument('minWidth', 'int', 'minimum width of the image'); + $this->registerArgument('minHeight', 'int', 'minimum height of the image'); + $this->registerArgument('maxWidth', 'int', 'maximum width of the image'); + $this->registerArgument('maxHeight', 'int', 'maximum height of the image'); + $this->registerArgument('absolute', 'bool', 'Force absolute URL', false, false); $this->registerArgument('context', 'string', 'context for image rendering', false, ProcessedFile::CONTEXT_IMAGEPREVIEW); } /** - * Resizes a given image (if required) and renders the respective img tag - * - * @see https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Image/ - * - * @throws Exception * @return string Rendered tag */ public function render() -- GitLab