From 86032d1dc8131fb35490e55429956296417e7f98 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 20 Mar 2020 15:56:59 +0100 Subject: [PATCH] wip #3511 --- src/app/Magic/EntityData.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/app/Magic/EntityData.php b/src/app/Magic/EntityData.php index 0ab065e..517ab0f 100644 --- a/src/app/Magic/EntityData.php +++ b/src/app/Magic/EntityData.php @@ -341,6 +341,33 @@ class EntityData implements \ArrayAccess return $this->_getAltOfMedia($media, $default); } + public function getImagesData($offset, $conversionName = '', $defaultImage = null, $defaultAlt = '') + { + $media = $this->getMedia($offset); + $d = ['url' => $defaultImage, 'alt' => $defaultAlt]; + + if (!$media) { + return [$d]; + } + + $res = []; + foreach ($media as $item) { + $res[] = $this->getImageDataFromMedia($item, $conversionName, $defaultImage, $defaultAlt); + } + return $res; + } + + public function getImageDataFromMedia(Media $media, $conversionName = '', $defaultImage = null, $defaultAlt = '') + { + $res = ['url' => $defaultImage, 'alt' => $defaultAlt]; + $url = $media->getUrl($conversionName); + if ($url) { + $res['url'] = $url; + } + $res['alt'] = $media->getCustomProperty('alt', $defaultAlt); + return $res; + } + public function getImageURLAt($offset, $at = 0, $conversionName = '', $default = null) { -- 2.39.5