Problem/Motivation

#3359421: (Re-)Add width / height also on fallback image and #3192234: Apply width and height attributes to allow responsive image tag use loading="lazy" added width/height attributes on fallback images. If the responsive_image variables are missing either of these keys they are stripped at the very start of the preprocessor

  if (isset($variables['width']) && empty($variables['width'])) {
    unset($variables['width']);
    unset($variables['height']);
  }
  elseif (isset($variables['height']) && empty($variables['height'])) {
    unset($variables['width']);
    unset($variables['height']);
  }

Steps to reproduce

Render something with

$build = [
  '#theme' => 'responsive_image_formatter',
  '#responsive_image_style_id' => 'some_id',
  '#uri' => 'blah',
];

And do not add width or height variables.

Proposed resolution

NULL checks on the fallback.

Issue fork drupal-3375721

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

acbramley created an issue. See original summary.

recrit’s picture

Status: Active » Needs work

The fix in the MR worked for me. I set to "Needs work" since this needs tests for the missing width and height keys.

hchonov’s picture

StatusFileSize
new1.09 KB

Static patch for the MR:

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

majid.ali’s picture

StatusFileSize
new1.2 KB

Adding static patch for MR based on latest https://git.drupalcode.org/project/drupal/-/merge_requests/4416

MR works so changing status to needs review.

majid.ali’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

MR appears to be red and probably needs test coverage right? Maybe small enough not

acbramley’s picture

MR just needed a rebase. I would think test coverage would be a lot of effort for something so trivial but I'm not sure.

recrit’s picture

StatusFileSize
new952 bytes

static patch of latest MR 4416