Skip to content

Commit

Permalink
TASK: Do not create an AssetImageSource if no asset was given
Browse files Browse the repository at this point in the history
  • Loading branch information
mficzel committed Jul 17, 2018
1 parent 8781326 commit 7f2718a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
11 changes: 7 additions & 4 deletions Classes/FusionObjects/AbstractImageSourceImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ public function getPreset()
/**
* Create helper and initialize width and height
*
* @return ImageSourceHelperInterface
* @return ImageSourceHelperInterface|null
*/
public function evaluate() : ImageSourceHelperInterface
public function evaluate() : ?ImageSourceHelperInterface
{
$helper = $this->createHelper();
if (is_null($helper)) {
return $helper;
}

if ($preset = $this->getPreset()) {
$helper->applyPreset($preset);
Expand All @@ -58,7 +61,7 @@ public function evaluate() : ImageSourceHelperInterface
/**
* Create helper
*
* @return ImageSourceHelperInterface
* @return ImageSourceHelperInterface|null
*/
abstract protected function createHelper() : ImageSourceHelperInterface;
abstract protected function createHelper() : ?ImageSourceHelperInterface;
}
8 changes: 6 additions & 2 deletions Classes/FusionObjects/AssetImageSourceImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ public function getAsync()
/**
* Create helper and initialize with the default values
*
* @return ImageSourceHelperInterface
* @return ImageSourceHelperInterface|null
*/
public function createHelper() : ImageSourceHelperInterface
public function createHelper() : ?ImageSourceHelperInterface
{
$asset = $this->getAsset();
if (!$asset) {
return null;
}

$helper = new AssetImageSourceHelper($asset);
$helper->setAsync((bool)$this->getAsync());
$helper->setRequest($this->getRuntime()->getControllerContext()->getRequest());
Expand Down
4 changes: 2 additions & 2 deletions Classes/FusionObjects/DummyImageSourceImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public function getText()
/**
* Create helper and initialize with the default values
*
* @return ImageSourceHelperInterface
* @return ImageSourceHelperInterface|null
*/
public function createHelper() : ImageSourceHelperInterface
public function createHelper() : ?ImageSourceHelperInterface
{
$uriBuilder = $this->runtime->getControllerContext()->getUriBuilder()->reset()->setCreateAbsoluteUri(true);
$baseUri = $uriBuilder->uriFor('image', [], 'DummyImage', 'Sitegeist.Kaleidoscope');
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Fusion/Prototypes/Image.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) {
title = null

renderer = afx`
<img
<img @if.has={props.imageSource}
src={props.imageSource}
srcset={props.sizes ? props.imageSource.widthSrcset(Array.keys(props.sizes)) : (props.resolutions ? props.imageSource.resolutionSrcset(props.resolutions) : null)}
sizes={props.sizes ? Array.join(props.sizes, ', ') : null}
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Fusion/Prototypes/Picture.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
title = null

renderer = afx`
<picture>
<picture @if.has={props.imageSource}>
<Neos.Fusion:Collection collection={props.sources} itemName="source" @children="itemRenderer" @if.has={props.sources}>
<source
@if.hasResolutions={source.resolutions}
Expand Down

0 comments on commit 7f2718a

Please sign in to comment.