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

CommentFileSizeAuthor
#4 undefined-array-key-3375638-4.patch1.51 KBsundhar
Command icon 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

joelseguin created an issue. See original summary.

acbramley’s picture

I believe this is a core issue that was caused by #3359421: (Re-)Add width / height also on fallback image

Jeya sundhar made their first commit to this issue’s fork.

sundhar’s picture

StatusFileSize
new1.51 KB
sundhar’s picture

Status: Active » Needs review
joelseguin’s picture

Thanks @Jeya sundhar - I can confirm that the patch worked perfectly after testing against the same site making use of the "Responsive background image" formatter.

sundhar’s picture

Hi @Pol Dellaiera
Thanks for the review.
Condition updated. file_exists checked before getting image size. :)

sundhar’s picture

Hi @Pol Dellaiera
Proposal of something smaller without almost no local variables changes updated. :+1

sundhar’s picture

Hi @Pol Dellaiera :)
$uri used instead of $url. Coding standard fixes updated :+1

  • Pol committed f7d3bbc7 on 8.x-1.x authored by Jeya sundhar
    Issue #3375638: Undefined array key "height" and "width" when using "...
frankdesign’s picture

Patch 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

pol’s picture

@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 ?

joelseguin’s picture

@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.

frankdesign’s picture

My 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

alex.verhoeven’s picture

Patch 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!

pol’s picture

The MR has been merged already, what are you talking about?

alex.verhoeven’s picture

My apologies, Pol, I misspoke! I meant rolled into a new release for use in production.

joseph.olstad’s picture

Status: Needs review » Fixed

Fixed by upgrading to 1.17

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.