Skip to content

Commit

Permalink
Merge pull request #5 from sitegeist/svg-assets
Browse files Browse the repository at this point in the history
BUGFIX: Add fallback to UriImageSourceHelper for SVG images
  • Loading branch information
mficzel committed Oct 18, 2018
2 parents 19db6f2 + 68e14fc commit 117eb7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
21 changes: 20 additions & 1 deletion Classes/FusionObjects/AssetImageSourceImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
namespace Sitegeist\Kaleidoscope\FusionObjects;

use Neos\Flow\Annotations as Flow;
use Neos\Flow\ResourceManagement\ResourceManager;
use Sitegeist\Kaleidoscope\EelHelpers\ImageSourceHelperInterface;
use Sitegeist\Kaleidoscope\EelHelpers\AssetImageSourceHelper;
use Neos\Fusion\FusionObjects\AbstractFusionObject;
use Sitegeist\Kaleidoscope\EelHelpers\UriImageSourceHelper;

class AssetImageSourceImplementation extends AbstractImageSourceImplementation
{
/**
* @Flow\Inject
* @var ResourceManager
*/
protected $resourceManager;

/**
* @var array
*/
protected $nonScalableMediaTypes = [
'image/svg+xml'
];

/**
* @return mixed
*/
Expand Down Expand Up @@ -36,6 +50,11 @@ public function createHelper() : ?ImageSourceHelperInterface
return null;
}

if (in_array($asset->getResource()->getMediaType(), $this->nonScalableMediaTypes)) {
$uri = $this->resourceManager->getPublicPersistentResourceUri($asset->getResource());
return new UriImageSourceHelper($uri);
}

$helper = new AssetImageSourceHelper($asset);
$helper->setAsync((bool)$this->getAsync());
$helper->setRequest($this->getRuntime()->getControllerContext()->getRequest());
Expand Down
1 change: 0 additions & 1 deletion Classes/FusionObjects/DummyImageSourceImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Neos\Flow\Annotations as Flow;
use Sitegeist\Kaleidoscope\EelHelpers\ImageSourceHelperInterface;
use Sitegeist\Kaleidoscope\EelHelpers\DummyImageSourceHelper;
use Neos\Fusion\FusionObjects\AbstractFusionObject;

class DummyImageSourceImplementation extends AbstractImageSourceImplementation
{
Expand Down
1 change: 0 additions & 1 deletion Classes/FusionObjects/UriImageSourceImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use Neos\Flow\Annotations as Flow;
use Sitegeist\Kaleidoscope\EelHelpers\ImageSourceHelperInterface;
use Sitegeist\Kaleidoscope\EelHelpers\ResourceImageSourceHelper;
use Neos\Fusion\FusionObjects\AbstractFusionObject;
use Sitegeist\Kaleidoscope\EelHelpers\UriImageSourceHelper;

Expand Down

0 comments on commit 117eb7e

Please sign in to comment.