From 06640f91afac97de70acdec990a1a4dc79473923 Mon Sep 17 00:00:00 2001 From: Oliver Bartsch <bo@cedev.de> Date: Fri, 6 Aug 2021 11:07:30 +0200 Subject: [PATCH] [BUGFIX] Instantiate ImageService in ImageViewHelper constructor In #94491 the injection of the ImageService in the ImageViewHelper was replaced by instantiating with GeneralUtility. This was done, since the ImageViewHelper is also used in the install tool, where no DI of this service is possible. However, since ImageService can be extended by third-party ViewHelpers, this then broke when accessing $this->imageService. This is now fixed by instantiating and assigning the ImageService in the constructor to the $imageService class variable. This way the DI is still not used, but backwards compatibility is given. Resolves: #94728 Related: #94491 Releases: master Change-Id: Id029a01f7f4f6dabdb2b148ac7b9efcca0f7b0fc Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70245 Tested-by: David Steeb <david.steeb@b13.com> Tested-by: core-ci <typo3@b13.com> Tested-by: Ruben Steeb <ruben.steeb@gmail.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: David Steeb <david.steeb@b13.com> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Ruben Steeb <ruben.steeb@gmail.com> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Oliver Bartsch <bo@cedev.de> --- .../ViewHelpers/ThumbnailViewHelper.php | 2 +- .../Classes/ViewHelpers/ImageViewHelper.php | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php index 0b7219c6c24e..45f9c9b9e4bc 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php @@ -85,7 +85,7 @@ class ThumbnailViewHelper extends ImageViewHelper } try { - $image = $this->getImageService()->getImage((string)$this->arguments['src'], $this->arguments['image'], (bool)$this->arguments['treatIdAsReference']); + $image = $this->imageService->getImage((string)$this->arguments['src'], $this->arguments['image'], (bool)$this->arguments['treatIdAsReference']); $cropString = $this->arguments['crop']; if ($cropString === null && $image->hasProperty('crop') && $image->getProperty('crop')) { diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php index fa95be3ba36a..1f6a12c80eea 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php @@ -95,6 +95,14 @@ class ImageViewHelper extends AbstractTagBasedViewHelper */ protected $tagName = 'img'; + protected ImageService $imageService; + + public function __construct() + { + parent::__construct(); + $this->imageService = GeneralUtility::makeInstance(ImageService::class); + } + /** * Initialize arguments. */ @@ -155,8 +163,7 @@ class ImageViewHelper extends AbstractTagBasedViewHelper } } else { try { - $imageService = $this->getImageService(); - $image = $imageService->getImage($src, $this->arguments['image'], (bool)$this->arguments['treatIdAsReference']); + $image = $this->imageService->getImage($src, $this->arguments['image'], (bool)$this->arguments['treatIdAsReference']); $cropString = $this->arguments['crop']; if ($cropString === null && $image->hasProperty('crop') && $image->getProperty('crop')) { $cropString = $image->getProperty('crop'); @@ -176,8 +183,8 @@ class ImageViewHelper extends AbstractTagBasedViewHelper if (!empty($this->arguments['fileExtension'] ?? '')) { $processingInstructions['fileExtension'] = $this->arguments['fileExtension']; } - $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); - $imageUri = $imageService->getImageUri($processedImage, $this->arguments['absolute']); + $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions); + $imageUri = $this->imageService->getImageUri($processedImage, $this->arguments['absolute']); if (!$this->tag->hasAttribute('data-focus-area')) { $focusArea = $cropVariantCollection->getFocusArea($cropVariant); @@ -214,9 +221,4 @@ class ImageViewHelper extends AbstractTagBasedViewHelper } return $this->tag->render(); } - - protected function getImageService(): ImageService - { - return GeneralUtility::makeInstance(ImageService::class); - } } -- GitLab