getBreakpointGroup() called on null

Created on 9 January 2025, 13 days ago

Problem/Motivation

In image_sizes.module this call causes a fatal:
Error: Call to a member function getBreakpointGroup() on null in image_sizes_theme_suggestions_responsive_image_formatter_alter() (line 80 of modules/contrib/image_sizes/image_sizes.module).

In my case, this one $responsive_image_style_storage->load($variables['responsive_image_style_id']); returns null, because $variables['responsive_image_style_id'] is empty, as an original image is rendered.

Of course, we could avoid calling any image_sizes functionality, when not attempting to render an image derivative.

But as a method call on null should never happen, i think a sanity check prior to the call, is always a good way to avoid such errors. In my case, this would be sufficient.

Proposed resolution

As mentioned above, sth like

if (!($responsive_image_style instanceof ResponsiveImageStyleInterface)) {
    return;
  }

prior to the call would be sufficient, not only for my case, but for all others too.

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇩🇪Germany drupatz

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024