Skip to content

Commit

Permalink
Add absolute url parameter for MediaStructure::getStructure.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilov committed Apr 16, 2018
1 parent 1a5057f commit 63f8418
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions Util/MediaStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,38 +54,43 @@ public function setImagineHelper($imagineHelper)
}

/**
* @param array $medias
* @param array $medias
* @param string $thumbnailFilter
* @param bool $securedId
* @param bool $securedId
* @param bool $isAbsolute
* @return array
*/
public function getStructure(array $medias, $thumbnailFilter = null, $securedId = false)
public function getStructure(array $medias, $thumbnailFilter = null, $securedId = false, $isAbsolute = false)
{
$structure = array_map(function (Media $media) use ($thumbnailFilter, $securedId) {
return $this->getMediaStructure($media, $thumbnailFilter, $securedId);
$structure = array_map(function (Media $media) use ($thumbnailFilter, $securedId, $isAbsolute) {
return $this->getMediaStructure($media, $thumbnailFilter, $securedId, $isAbsolute);
}, $medias);

return $structure;
}

/**
* @param MediaInterface $media
* @param string $thumbnailFilter
* @param bool $securedId
* @param string $thumbnailFilter
* @param bool $securedId
* @param bool $isAbsolute
* @return array
* @throws Exception
*/
public function getMediaStructure(MediaInterface $media, $thumbnailFilter = null, $securedId = false)
public function getMediaStructure(MediaInterface $media, $thumbnailFilter = null, $securedId = false, $isAbsolute = false)
{
$thumbnailPath = $this->mediaHelper->getThumbnailPath($media);
$contentPath = $this->mediaHelper->getContentPath($media);
$contentPath = $this->mediaHelper->getContentPath($media, $isAbsolute);

if ($thumbnailFilter) {
if (!$this->imagineHelper instanceof ImagineHelper) {
throw new Exception('ImagineHelper is not defined. You need use Liip\ImagineBundle.');
}

$thumbnailPath = $this->mediaHelper->getThumbnailPath($media, false);
$thumbnailPath = $this->imagineHelper->filter($thumbnailPath, $thumbnailFilter);

} else {
$thumbnailPath = $this->mediaHelper->getThumbnailPath($media, $isAbsolute);
}

return [
Expand Down

0 comments on commit 63f8418

Please sign in to comment.