Problem/Motivation
When viewing or editing a node with an attached image after deleting that image from admin/content/file, an message like Warning: array_key_exists() expects parameter 2 to be array, null given in theme_image_formatter() (line 605 of modules/image/image.field.inc). is generated.
Steps to reproduce in comment #5.
Proposed resolution
Check-for and handle this case so an error is not emitted.
Remaining tasks
Unknown.
User interface changes
None.
API changes
Unknown.
Original report by @MiroslavBanov
This error shows when an image is removed in files administration, but it has usage in nodes:
Warning: array_key_exists() expects parameter 2 to be array, null given in theme_image_formatter()
The problem is related to this issue, which solves similar problems for missing file attachments: https://drupal.org/node/2132383
I've attached a patch that tries to remove file field items for missing files.
| Comment | File | Size | Author |
|---|---|---|---|
| file_entity-filter_out_missing_files.patch | 545 bytes | miroslavbanov |
Comments
Comment #1
miroslavbanov commentedComment #2
miroslavbanov commentedComment #3
dave reidCan you give me more details on what field formatter and file type display configurations I should use to try and reproduce this? I feel that this could be fixed in a better place rather than having to run an array_filter().
Comment #4
miroslavbanov commentedNot sure why this happens. I have a complex environment, with Workbench moderation, media_multiupload, and more. The problem happened after I delete a file (from admin/content/file) that is being used by a node. I had other notices as well, on non-image files too. And this patch doesn't even solve non-image files.
I'm closing for now, and will reopen if I figure out how to reproduce on normal environments, and what really causes this.
Comment #5
mparker17I have been able to reproduce this:
drush -y pm-download drupal-7.x ; drush -y site-install.drush -y dl file_entity-7.x-2.x media-7.x-2.x.admin/structure/typesand add a content type namedPhoto gallery.admin/structure/types/manage/photo-gallery/fieldsand add an image field. Set the widget type toMedia browser. In the field settings, enable theUploadandLibrarybrowser plugins.node/add/photo-galleryand add a photo gallery node. Upload one or more images to the image field.admin/content/fileand delete one of the images you uploaded.admin/reports/dblog. Note there are no errors in the log.admin/reports/dblog. Note that aWarning: array_key_exists() expects parameter 2 to be array, null given in theme_image_formatter()message has been added to the recent log messages.admin/reports/dblog. Note that anotherWarning: array_key_exists() expects parameter 2 to be array, null given in theme_image_formatter()message has been added to the recent log messages.Comment #6
mparker17Put link to steps to reproduce in issue summary.
Comment #7
miroslavbanov commentedThis is the code that I use to fix it for myself in a custom module:
Comment #8
mstrelan commentedPerhaps when files are deleted from admin/content/file there should be a warning that the file is associated with one or more entities, and if it's still confirmed to delete the file the entities should be updated appropriately.
Comment #9
dave reidThis is a duplicate of a core bug that image field does not handle deleted items properly: #920840: Broken images displayed and PHP notices when file/image field values are missing
Comment #10
varsharani commentedThis warning showing me in drupal8.
Warning: array_key_exists() expects parameter 2 to be array, null given in Drupal\image\Plugin\Field\FieldWidget\ImageWidget::validateRequiredFields() (line 263 of core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php)
Comment #11
screon commentedVarsharani, I've got the same error. Did you manage to solve it? I'm still backtracing.
Comment #12
loopy1492 commentedCan confirm that upgrading this module to the most recent version, then applying the core patch at #920840 should solve the issue.