From d72816086f3b8708fae4b0ac1e3b8c7f23db772d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edi=20Modri=C4=87?= Date: Thu, 19 May 2022 11:34:32 +0200 Subject: [PATCH] Return an empty variation if image does not exist This prevents exceptions with `Impossible to access an attribute ("uri") on a null variable.` in Twig (cherry picked from commit 3779361a109f99cc40093cce832ef33d70a4423c) --- bundle/Templating/Twig/Extension/ImageRuntime.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/Templating/Twig/Extension/ImageRuntime.php b/bundle/Templating/Twig/Extension/ImageRuntime.php index 75a17aa1..2c49bd52 100644 --- a/bundle/Templating/Twig/Extension/ImageRuntime.php +++ b/bundle/Templating/Twig/Extension/ImageRuntime.php @@ -41,7 +41,7 @@ public function __construct( * * @return null|\eZ\Publish\SPI\Variation\Values\Variation */ - public function getImageVariation(Field $field, string $variationName): ?Variation + public function getImageVariation(Field $field, string $variationName): Variation { /** @var \eZ\Publish\Core\FieldType\Image\Value $value */ $value = $field->value; @@ -60,6 +60,6 @@ public function getImageVariation(Field $field, string $variationName): ?Variati ); } - return null; + return new Variation(); } }