Problem/Motivation

Breaks with error
Notice: Undefined offset: 0 in Drupal\image_popup\Plugin\Field\FieldFormatter\ImagePopupFieldFormatter->viewElements() (line 182 of /var/www/html/web/modules/contrib/image_popup/src/Plugin/Field/FieldFormatter/ImagePopupFieldFormatter.php)

Also this registers a notice $image_style_popup_settings['effects'] if effects key is not present for styles. Better to check isset first.

Steps to reproduce

Let's say we have a View listing where a list of content in Teaser mode is rendered. Now if we set the formatter to use Image pop up for the image field, it is possible that some content may not have that image field as it may not a required field always. This breaks with the error given.

Proposed resolution

Check for empty files and return early.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

u_tiwari created an issue. See original summary.

u_tiwari’s picture

Issue summary: View changes
u_tiwari’s picture

This fixes the error and notice both.

JayKandari’s picture

Issue tags: +DIACWAug2020
Mithun S’s picture

Status: Active » Needs review

Moving the status to needs review as the patch applied by @u_tiwari needs to be reviewed.

pooja.nanwal’s picture

FileSize
613.91 KB
216.54 KB

Issue was reproducible . It worked fine i.e. no error received after applying the patch (no-image-field-3164767-3.patch).
Screenshot attached : Before Patch.png, After Patch #3.png

+1 for RTBC.

JayKandari’s picture

Version: 8.x-1.1 » 2.x-dev
Status: Needs review » Needs work
Issue tags: +DIACWSep2020

#3 needs a reroll. patch doesn't apply. Thanks!

❯ curl https://www.drupal.org/files/issues/2020-08-12/no-image-field-3164767-3.patch | git apply
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6553  100  6553    0     0   6978      0 --:--:-- --:--:-- --:--:--  6971
error: patch failed: src/Plugin/Field/FieldFormatter/ImagePopupFieldFormatter.php:1
error: src/Plugin/Field/FieldFormatter/ImagePopupFieldFormatter.php: patch does not apply
ankithashetty’s picture

Re-rolled the patch in #3. The solution provided by the patch worked for me as well!
Coding standard changes made in #3 has already been fixed in the latest version of the module, so updated the patch accordingly. Please review.

Before applying the patch:

After applying the patch:

Thank you!

JayKandari’s picture

Status: Needs review » Fixed
Issue tags: -DIACWAug2020, -DIACWSep2020 +DIACWOct2020

The 2.x branch was slightly changed. Applied the change on top of #8.

Committed & pushed to 2.x. Thank you all for contributions.

Status: Fixed » Closed (fixed)

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