From ac47d626b3533dc20af7426a4a0f38bd755e1ad0 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Thu, 6 Sep 2018 15:13:26 +0200 Subject: [PATCH] BUGFIX: setWidth and setHeight and applyPreset return an altered copy instead of modifying the imageSource This is necessary to render the same imageSource in different crops. --- .../EelHelpers/AbstractImageSourceHelper.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Classes/EelHelpers/AbstractImageSourceHelper.php b/Classes/EelHelpers/AbstractImageSourceHelper.php index 8a79a4d..1c90d92 100644 --- a/Classes/EelHelpers/AbstractImageSourceHelper.php +++ b/Classes/EelHelpers/AbstractImageSourceHelper.php @@ -29,14 +29,16 @@ abstract class AbstractImageSourceHelper implements ImageSourceHelperInterface public function setWidth(int $targetWidth = null) : ImageSourceHelperInterface { - $this->targetWidth = $targetWidth; - return $this; + $newSource = clone($this); + $newSource->targetWidth = $targetWidth; + return $newSource; } public function setHeight(int $targetHeight = null) : ImageSourceHelperInterface { - $this->targetHeight = $targetHeight; - return $this; + $newSource = clone($this); + $newSource->targetHeight = $targetHeight; + return $newSource; } /** @@ -47,22 +49,23 @@ public function setHeight(int $targetHeight = null) : ImageSourceHelperInterface */ public function applyPreset(string $name) : ImageSourceHelperInterface { + $newSource = clone($this); if ($this->thumbnailPresets) { $preset = Arrays::getValueByPath($this->thumbnailPresets, $name); if ($preset) { if ($width = Arrays::getValueByPath($preset, 'width')) { - $this->setWidth($width); + $newSource->setWidth($width); } elseif ($width = Arrays::getValueByPath($preset, 'maximumWidth')) { - $this->setWidth($width); + $newSource->setWidth($width); } if ($height = Arrays::getValueByPath($preset, 'height')) { - $this->setHeight($height); + $newSource->setHeight($height); } elseif ($height = Arrays::getValueByPath($preset, 'maximumHeight')) { - $this->setHeight($height); + $newSource->setHeight($height); } } } - return $this; + return $newSource; } /**