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.
Comment | File | Size | Author |
---|---|---|---|
#8 | Screenshot from 2020-09-15 23-05-49.png | 6.13 KB | ankithashetty |
#8 | Screenshot from 2020-09-15 23-05-35.png | 22.49 KB | ankithashetty |
#8 | diff_reroll_3164767_3-8.txt | 7.12 KB | ankithashetty |
#8 | 3164767-8.patch | 1.52 KB | ankithashetty |
#6 | After Patch #3.png | 216.54 KB | pooja.nanwal |
Comments
Comment #2
u_tiwari CreditAttribution: u_tiwari at Axelerant commentedComment #3
u_tiwari CreditAttribution: u_tiwari at Axelerant commentedThis fixes the error and notice both.
Comment #4
JayKandariComment #5
Mithun SMoving the status to needs review as the patch applied by @u_tiwari needs to be reviewed.
Comment #6
pooja.nanwal CreditAttribution: pooja.nanwal at Srijan | A Material+ Company for Drupal India Association commentedIssue 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.
Comment #7
JayKandari#3 needs a reroll. patch doesn't apply. Thanks!
Comment #8
ankithashettyRe-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!
Comment #10
JayKandariThe 2.x branch was slightly changed. Applied the change on top of #8.
Committed & pushed to 2.x. Thank you all for contributions.