Commit 7e6a9da5 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Benjamin Franzke
Browse files

[BUGFIX] Do not inject ImageService in ImageViewHelper

The ImageViewHelper is used in install tool context,
when sending the "login successful" or "login failed"
email, while using the SystemEmail layout. Since DI is
not fully available in install tool context, the ImageService
can not be injected in the view helper.

Resolves: #94491
Releases: master
Change-Id: I7eb4e0dda0738346032cf550119c3503523df0eb
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69726


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
parent a8ebadb6
......@@ -85,7 +85,7 @@ class ThumbnailViewHelper extends ImageViewHelper
}
try {
$image = $this->imageService->getImage((string)$this->arguments['src'], $this->arguments['image'], (bool)$this->arguments['treatIdAsReference']);
$image = $this->getImageService()->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')) {
......
......@@ -95,19 +95,6 @@ class ImageViewHelper extends AbstractTagBasedViewHelper
*/
protected $tagName = 'img';
/**
* @var \TYPO3\CMS\Extbase\Service\ImageService
*/
protected $imageService;
/**
* @param \TYPO3\CMS\Extbase\Service\ImageService $imageService
*/
public function injectImageService(ImageService $imageService)
{
$this->imageService = $imageService;
}
/**
* Initialize arguments.
*/
......@@ -168,7 +155,8 @@ class ImageViewHelper extends AbstractTagBasedViewHelper
}
} else {
try {
$image = $this->imageService->getImage($src, $this->arguments['image'], (bool)$this->arguments['treatIdAsReference']);
$imageService = $this->getImageService();
$image = $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');
......@@ -188,8 +176,8 @@ class ImageViewHelper extends AbstractTagBasedViewHelper
if (!empty($this->arguments['fileExtension'] ?? '')) {
$processingInstructions['fileExtension'] = $this->arguments['fileExtension'];
}
$processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
$imageUri = $this->imageService->getImageUri($processedImage, $this->arguments['absolute']);
$processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
$imageUri = $imageService->getImageUri($processedImage, $this->arguments['absolute']);
if (!$this->tag->hasAttribute('data-focus-area')) {
$focusArea = $cropVariantCollection->getFocusArea($cropVariant);
......@@ -226,4 +214,9 @@ class ImageViewHelper extends AbstractTagBasedViewHelper
}
return $this->tag->render();
}
protected function getImageService(): ImageService
{
return GeneralUtility::makeInstance(ImageService::class);
}
}
......@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ImageService;
use TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper;
use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
......@@ -182,8 +183,7 @@ class ImageViewHelperTest extends ViewHelperBaseTestcase
$imageService->expects(self::once())->method('getImage')->willReturn($image);
$imageService->expects(self::once())->method('applyProcessingInstructions')->with($image, self::anything())->willReturn($processedFile);
$imageService->expects(self::once())->method('getImageUri')->with($processedFile)->willReturn($expected['src']);
$this->viewHelper->injectImageService($imageService);
GeneralUtility::setSingletonInstance(ImageService::class, $imageService);
$tagBuilder = $this->getMockBuilder(TagBuilder::class)
->setMethods(['addAttribute', 'render'])
......@@ -296,8 +296,7 @@ class ImageViewHelperTest extends ViewHelperBaseTestcase
$imageService->expects(self::once())->method('getImage')->willReturn($image);
$imageService->expects(self::once())->method('applyProcessingInstructions')->with($image, self::anything())->willReturn($processedFile);
$imageService->expects(self::once())->method('getImageUri')->with($processedFile)->willReturn('test.png');
$this->viewHelper->injectImageService($imageService);
GeneralUtility::setSingletonInstance(ImageService::class, $imageService);
$tagBuilder = $this->getMockBuilder(TagBuilder::class)
->setMethods(['addAttribute', 'render'])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment