From 63947e19ad4cf0b740f1c664c7c1610c55634ee6 Mon Sep 17 00:00:00 2001 From: hudri Date: Fri, 19 Nov 2021 10:09:00 +0000 Subject: [PATCH] drupal_image: return first image by fid in case of ambiguous selector --- src/TwigTweakExtension.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/TwigTweakExtension.php b/src/TwigTweakExtension.php index ea04e2e..59e05a9 100644 --- a/src/TwigTweakExtension.php +++ b/src/TwigTweakExtension.php @@ -246,11 +246,13 @@ class TwigTweakExtension extends AbstractExtension { ->getStorage('file') ->loadByProperties([$selector_type => $selector]); - // To avoid ambiguity render nothing unless exact one image has been found. - if (count($files) != 1) { + if (count($files) < 1) { return []; } + // To avoid ambiguity order by fid. + ksort($files); + $file = reset($files); return \Drupal::service('twig_tweak.image_view_builder')->build($file, $style, $attributes, $responsive, $check_access); }