From 7f2718a8c32808542b30e5aff2d0f31033dcc8fb Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Tue, 17 Jul 2018 12:13:47 +0200 Subject: [PATCH] TASK: Do not create an AssetImageSource if no asset was given --- .../AbstractImageSourceImplementation.php | 11 +++++++---- .../FusionObjects/AssetImageSourceImplementation.php | 8 ++++++-- .../FusionObjects/DummyImageSourceImplementation.php | 4 ++-- Resources/Private/Fusion/Prototypes/Image.fusion | 2 +- Resources/Private/Fusion/Prototypes/Picture.fusion | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Classes/FusionObjects/AbstractImageSourceImplementation.php b/Classes/FusionObjects/AbstractImageSourceImplementation.php index f123591..232b2f9 100644 --- a/Classes/FusionObjects/AbstractImageSourceImplementation.php +++ b/Classes/FusionObjects/AbstractImageSourceImplementation.php @@ -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); @@ -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; } diff --git a/Classes/FusionObjects/AssetImageSourceImplementation.php b/Classes/FusionObjects/AssetImageSourceImplementation.php index 7db6819..55c27e9 100644 --- a/Classes/FusionObjects/AssetImageSourceImplementation.php +++ b/Classes/FusionObjects/AssetImageSourceImplementation.php @@ -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()); diff --git a/Classes/FusionObjects/DummyImageSourceImplementation.php b/Classes/FusionObjects/DummyImageSourceImplementation.php index 71150da..5fd2270 100644 --- a/Classes/FusionObjects/DummyImageSourceImplementation.php +++ b/Classes/FusionObjects/DummyImageSourceImplementation.php @@ -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'); diff --git a/Resources/Private/Fusion/Prototypes/Image.fusion b/Resources/Private/Fusion/Prototypes/Image.fusion index 318b776..97c560a 100644 --- a/Resources/Private/Fusion/Prototypes/Image.fusion +++ b/Resources/Private/Fusion/Prototypes/Image.fusion @@ -31,7 +31,7 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) { title = null renderer = afx` - +