Browse Source

drupal_image: return first image by fid in case of ambiguous selector

merge-requests/14/head
hudri 3 years ago
parent
commit
63947e19ad
  1. 6
      src/TwigTweakExtension.php

6
src/TwigTweakExtension.php

@ -246,11 +246,13 @@ class TwigTweakExtension extends AbstractExtension {
->getStorage('file') ->getStorage('file')
->loadByProperties([$selector_type => $selector]); ->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 []; return [];
} }
// To avoid ambiguity order by fid.
ksort($files);
$file = reset($files); $file = reset($files);
return \Drupal::service('twig_tweak.image_view_builder')->build($file, $style, $attributes, $responsive, $check_access); return \Drupal::service('twig_tweak.image_view_builder')->build($file, $style, $attributes, $responsive, $check_access);
} }

Loading…
Cancel
Save