Skip to content

Commit

Permalink
BUGFIX: setWidth and setHeight and applyPreset return an altered copy…
Browse files Browse the repository at this point in the history
… instead of modifying the imageSource

This is necessary to render the same imageSource in different crops.
  • Loading branch information
mficzel committed Sep 6, 2018
1 parent 55019bb commit ac47d62
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Classes/EelHelpers/AbstractImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit ac47d62

Please sign in to comment.