- Issue created by @mikee
@mikee On digging this issue I have found that this module overrides
ImageFormatter::viewElements
. viewElements() is called per item, so every item is getting first selector . Each of the items is rendered individually.
So according to the logic in this foreach loop on line number 573/** @var \Drupal\file\FileInterface $file */ foreach ($files as $delta => $file) $css_settings['bg_image_selector'] = $selectors[$delta % \count($selectors)];
The value of $delta always remains 0 , and only the first selector gets applied as viewElements() is called per item.
@mikee on dumping $files in BgImageFormatter.php , we can see that instead of getting all images in a single array or object , we are getting three separate individual array as viewElements() is getting called per image .
- Merge request !123485197-multivalue-field-not: Added static variable and fixed the multi value... → (Open) created by sourabhsisodia_
- 🇬🇧United Kingdom mikee
@sourabhsisodia many thanks for investigating and resolving this issue.
FYI, on my installation for the module I updated the file 'bg_image_formatter/src/Plugin/Field/FieldFormatter/BgImageFormatter.php' with your updated version of the file and the Multivalue field for Media items is working.
I copied your version from: https://git.drupalcode.org/project/bg_image_formatter/-/blob/c17f8a16707...
To confirm, after making the above update the source code for the page outputs all the images using the appropriate selectors ".bg1, .bg2, .bg3, .bg4, .bg5, .bg6".
The below shows the correct source code being generating by the module (8.x-1.17) + your updated file (BgImageFormatter.php) :
<style media="all">.bg6 {background-image: url('https://d10-cbd-dev.ddev.site/sites/default/files/2021-12/hanex-picker.jpg') ;}</style> <style media="all">.bg5 {background-image: url('https://d10-cbd-dev.ddev.site/sites/default/files/2021-12/avonite-picker.jpg') ;}</style> <style media="all">.bg4 {background-image: url('https://d10-cbd-dev.ddev.site/sites/default/files/2022-07/corian-bath-drainer.png') ;}</style> <style media="all">.bg3 {background-image: url('https://d10-cbd-dev.ddev.site/sites/default/files/2022-07/corian-bath-delight-8430.png') ;}</style> <style media="all">.bg2 {background-image: url('https://d10-cbd-dev.ddev.site/sites/default/files/2022-07/corian-bath-delight-8420.png') ;}</style> <style media="all">.bg1 {background-image: url('https://d10-cbd-dev.ddev.site/sites/default/files/2022-07/corian-bath-delight-8410.png') ;}</style>
Many thanks for resolving this issue.
- Status changed to RTBC
20 days ago 12:19pm 2 January 2025 - 🇮🇳India sayan_k_dutta
Reviewed the changes. Looks good. Attaching screenshot of the same and moving to RTBC.