Problem/Motivation
The "Responsive Background Image" formatter is throwing a warning with Drupal 10.1+.
The following is a snippet of the error (in French) is the Drupal log:
Warning : Undefined array key "width" dans template_preprocess_responsive_image() (/var/www/html/web/core/modules/responsive_image/responsive_image.module ligne 209)
#0 /var/www/html/web/core/includes/bootstrap.inc(164): _drupal_error_handler_real(2, 'Undefined array...', '/var/www/html/w...', 209)
#1 /var/www/html/web/core/modules/responsive_image/responsive_image.module(209): _drupal_error_handler(2, 'Undefined array...', '/var/www/html/w...', 209)
#2 /var/www/html/web/modules/contrib/bg_image_formatter/modules/responsive_bg_image_formatter/src/Plugin/Field/FieldFormatter/ResponsiveBgImageFormatter.php(105): template_preprocess_responsive_image(Array)
#3 /var/www/html/web/core/lib/Drupal/Core/Field/FormatterBase.php(89): Drupal\responsive_bg_image_formatter\Plugin\Field\FieldFormatter\ResponsiveBgImageFormatter->viewElements(Object(Drupal\file\Plugin\Field\FieldType\FileFieldItemList), 'fr')...
This issue may relate to the following core issue:
https://www.drupal.org/project/drupal/issues/3359421
** The patch found in the issue above could not be applied to D10.1+ so I was not able to test it out.
Steps to reproduce
Use the "Responsive Background Image" formatter on a media display. Make use of the media display in the front-end of a site and navigate to the page.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | undefined-array-key-3375638-4.patch | 1.51 KB | sundhar |
Issue fork bg_image_formatter-3375638
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
acbramley commentedI believe this is a core issue that was caused by #3359421: (Re-)Add width / height also on fallback image
Comment #4
sundharComment #5
sundharComment #6
joelseguinThanks @Jeya sundhar - I can confirm that the patch worked perfectly after testing against the same site making use of the "Responsive background image" formatter.
Comment #8
sundharHi @Pol Dellaiera
Thanks for the review.
Condition updated. file_exists checked before getting image size. :)
Comment #9
sundharHi @Pol Dellaiera
Proposal of something smaller without almost no local variables changes updated. :+1
Comment #10
sundharHi @Pol Dellaiera :)
$uri used instead of $url. Coding standard fixes updated :+1
Comment #12
frankdesign commentedPatch is not working for me I'm afraid. I applied it today to 8.x-1.16 on Drupal 10.1.4 and PHP 8.1.24
Before the patch, I was getting the same error as above.
After the patch (which applies no problem), there is no error but no background image appears. There is no error in the logs either.
Am I missing something? Is there a setting I need to change somewhere?
P.S. I have Responsive Background Images working fine on all my other sites which are still D9.5
Comment #13
pol@Jeya sundhar: Could you double check if you haven't missed anything?
@frankdesign: Are you able to spot the issue while tweaking a bit the changes that were introduced ?
Comment #14
joelseguin@frankdesign the latest patch (from MR 6) is working nicely for me. No errors in the logs. Both background image and responsive background image formatters work as expected with background images appearing on the frontend of the site.
Comment #15
frankdesign commentedMy bad. I found a change (as part of upgrading to D10) in the theme template files for Media that prevented Background Images Formatter from working. Once I fixed that, both background image and responsive background image formatters are working perfectly after applying the patch.
Thanks @Pol and @joelseguin for confirming it was working for you.
F
Comment #16
alex.verhoeven commentedPatch is also working well for me. Any chance we can get this merged? It would wonderful to kill these warnings.
Thanks for working on this for us!
Comment #17
polThe MR has been merged already, what are you talking about?
Comment #18
alex.verhoeven commentedMy apologies, Pol, I misspoke! I meant rolled into a new release for use in production.
Comment #19
joseph.olstadFixed by upgrading to 1.17