Empty responsive image style crashes the site upon editing node/media

Created on 31 May 2024, 28 days ago
Updated 14 June 2024, 14 days ago

Problem/Motivation

It's possible for the $settings['responsive_image_style'] value to be an empty string, meaning this check:

    if (isset($settings['responsive_image_style'])) {
      // Try to determine image style based on responsive image style.
      /** @var \Drupal\responsive_image\Entity\ResponsiveImageStyle $responsive_image_style */
      $responsive_image_style = ResponsiveImageStyle::load($settings['responsive_image_style']);

Doesn't work, and it tries to load an empty string as a ResponsiveImageStyle, throwing the following error:

Error: Call to a member function getImageStyleMappings() on null in Drupal\contextual_image_widget_crop\Plugin\Field\FieldWidget\ContextualImageCropMediaLibraryWidget->getImageStyles() (line 160 of ~/web/modules/contrib/contextual_image_widget_crop/src/Plugin/Field/FieldWidget/ContextualImageCropMediaLibraryWidget.php).

Steps to reproduce

Not entirely sure, I messed with the display settings a bit but couldn't find a stable way to reproduce. It does happen sometimes..

Proposed resolution

Change `isset` to `!empty`, which will cover all cases (null, empty string, non-existent, ..)

Remaining tasks

I'll create a MR that applies the fix.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium RandalV

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024