Skip to content

Commit

Permalink
Added support for size config object in getImageObject()
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Jul 17, 2018
1 parent b674d36 commit b1c4bb5
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/Element/CustomElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace MadeYourDay\RockSolidCustomElements\Element;

use Contao\Image\PictureConfigurationInterface;
use MadeYourDay\RockSolidColumns\Element\ColumnsStart;
use MadeYourDay\RockSolidCustomElements\Template\CustomTemplate;
use MadeYourDay\RockSolidCustomElements\CustomElements;
Expand Down Expand Up @@ -177,12 +178,12 @@ protected function deserializeDataRecursive($data)
/**
* Get an image object from id/uuid and an optional size configuration
*
* @param int|string $id ID, UUID string or binary
* @param string|array $size [width, height, mode] optionally serialized
* @param int $maxSize Gets passed to addImageToTemplate as $intMaxWidth
* @param string $lightboxId Gets passed to addImageToTemplate as $strLightboxId
* @param array $item Gets merged and passed to addImageToTemplate as $arrItem
* @return object Image object (similar as addImageToTemplate)
* @param int|string $id ID, UUID string or binary
* @param string|array|PictureConfigurationInterface $size [width, height, mode] optionally serialized or a config object
* @param int $maxSize Gets passed to addImageToTemplate as $intMaxWidth
* @param string $lightboxId Gets passed to addImageToTemplate as $strLightboxId
* @param array $item Gets merged and passed to addImageToTemplate as $arrItem
* @return object Image object (similar as addImageToTemplate)
*/
public function getImageObject($id, $size = null, $maxSize = null, $lightboxId = null, $item = array())
{
Expand Down Expand Up @@ -213,22 +214,24 @@ public function getImageObject($id, $size = null, $maxSize = null, $lightboxId =
return null;
}

if (is_string($size) && trim($size)) {
$size = \StringUtil::deserialize($size);
}
if (!is_array($size)) {
$size = array();
if (!$size instanceof PictureConfigurationInterface) {
if (is_string($size) && trim($size)) {
$size = \StringUtil::deserialize($size);
}
if (!is_array($size)) {
$size = array();
}
$size[0] = isset($size[0]) ? $size[0] : 0;
$size[1] = isset($size[1]) ? $size[1] : 0;
$size[2] = isset($size[2]) ? $size[2] : 'crop';
}
$size[0] = isset($size[0]) ? $size[0] : 0;
$size[1] = isset($size[1]) ? $size[1] : 0;
$size[2] = isset($size[2]) ? $size[2] : 'crop';

$imageItem = array(
'id' => $image->id,
'uuid' => isset($image->uuid) ? $image->uuid : null,
'name' => $file->basename,
'singleSRC' => $image->path,
'size' => serialize($size),
'size' => $size,
);

$imageItem = array_merge($imageItem, $item);
Expand Down

0 comments on commit b1c4bb5

Please sign in to comment.