Cannot generate image URL for images style "_original image_" and "_empty image_"

Created on 21 March 2023, over 1 year ago
Updated 22 November 2023, 10 months ago

Problem/Motivation

If the "original image" or "empty image" option is used at a breakpoint in a responsive image style, no image URL can be generated.

Error: Call to a member function buildUrl() on null in Drupal\responsive_image_preload\PreloadGenerator->generatePreloadsForDelta() (Zeile 144 in /responsive_image_preload/src/PreloadGenerator.php)

Steps to reproduce

Create a responsive image style and select the original image for a breakpoint.
Configure an image field with the responsive image style and enable preloading.

Proposed resolution

Catch the image style names "_original image_" and "_empty image_" or the empty $image_style variable and use the original image url instead.

🐛 Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

🇩🇪Germany J-Lee 🇩🇪🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @J-Lee
  • 🇩🇪Germany J-Lee 🇩🇪🇪🇺

    A quick and dirty fix:

    \Drupal\responsive_image_preload\PreloadGenerator::generatePreloadsForDelta() #144:

    case 'image_style':
                  $image_style_name = $image_style_mapping['image_mapping'];
                  /** @var \Drupal\image\ImageStyleInterface $image_style */
                  $image_style = $image_style_storage->load($image_style_name);
                  $url = $image_style ? $image_style->buildUrl($file->getFileUri()) : $file->getFileUri();
                  $image_url = $this->fileUrlGenerator->generateString($url);
    
  • 🇮🇳India anchal_gupta

    I have uploaded the patch

  • 🇩🇪Germany J-Lee 🇩🇪🇪🇺
  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany J-Lee 🇩🇪🇪🇺
  • Status changed to Needs work 10 months ago
  • 🇺🇸United States luke.leber Pennsylvania

    Wow, I'm sorry. This issue never reached my inbox!

    I'll try to find some time to get this evaluated. My gut is saying we skip the empty image (since it's an inline data: source -- preloading won't make any difference here) and treat the original image as the patch in #3 suggests.

    This also needs some extended test coverage to trigger a failure in Drupal CI before a patch can be committed to fix it.

Production build 0.71.5 2024