When a field is empty and no image is present, the module tries to build a new FocalPoint object with an empty target_id parameter, resulting in a warning. This patch adds a check to make sure that the image field is set.

CommentFileSizeAuthor
focal_point_no_image.patch759 bytesfloretan

Comments

floretan created an issue. See original summary.

bleen’s picture

Can you put some steps to reproduce. I see what your code is doing, but I cant see how that would ever happen

floretan’s picture

On a clean Drupal 8 installation (standard installation profile) with the focal_point module enabled. Create an article node, but leaving the image field empty. After submitting the node form, you have the following in the database log:

Notice: Undefined index: target_id in Drupal\focal_point\Plugin\Field\FieldWidget\FocalPointImageWidget::value() (line 96 of [..]/modules/focal_point/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php).
bleen’s picture

Status: Needs review » Fixed

Finally got around to checking this out. Looks good, thanks!!

  • bleen18 committed 99fd1d8 on 8.x-1.x authored by floretan
    Issue #2565519 by floretan: PHP warning when field is empty
    

Status: Fixed » Closed (fixed)

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