Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
image system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
23 Sep 2010 at 17:30 UTC
Updated:
16 Sep 2022 at 20:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
nagba commentedComment #2
dagmarComment #4
aaron commentedsubscribe. i think you need to reroll the patch from the docroot.
Comment #5
nagba commentedty.
Comment #6
nagba commentedComment #7
Anonymous (not verified) commentedThis fix works.
The patch needs to be rerolled now that we're on git and working against Drupal 8. I think it should also check for empty instead of
!$item.Comment #8
claudiu.cristeaThis has been fixed in D8 conversion.
Comment #9
hefox commentedThis is still an issue in 7.x, looking to see if any other issues for it already open though.
Comment #10
hefox commentedunable to find an active other issue.
reroll with array_filter
this bug leads to: array_key_exists() expects parameter 2 to be array, null given in theme_image_formatter() (line 605 of .. modules/image/image.field.inc).
Comment #11
hefox commentedNot that part of the issue is that the deleted file IDs aren't deleted from the database also. References and taxonomy terms also has this issue to my knowledge and it's not an easy fix
Comment #12
hefox commentedPatch is being used on a project with multiple testers/developers and has not presented any problems yet and has fixed the issue.
Comment #13
dave reidI think we need the array_filter in file_field_load() instead. I think this is too high-up of a fix.
Comment #14
dave reidI actually think we need the same fix we did for file_field_presave() in #1443158: file_field_presave assumes that a file object has been loaded
Comment #15
rreiss commented#10 fixed the
warnings for me.
Thanks!
Comment #16
dave reidLet's do this instead.
Comment #17
Ali.Geyik commented#10 and #16 patches didn't work for me, user1 still can't upload/change his profile picture :(
Comment #18
mgiffordUnassigning from @nagba as it's been a few years.
Comment #19
dave reidComment #20
Tommy_001 commented#5 saved my life. Thanks! I cannot figure out why the error produced though, because no images failed to load during the migration of a certain node type. But with this patch everything looks as it should again.
Comment #21
nickonom commented#10 made the error message go.
Comment #22
andy inman commentedAs I wanted a fix for this without patching core, I implemented the following in a custom module. This also logs an error if the referenced file is not accessible (deleted etc.)
Comment #23
dan1eln1el5en commented#22 that is a very cool fix.
Funny, how such an old issue still relies on patch-work.
Comment #24
mustanggb commentedJust ran into this over in #2816413: Handle NULL images nicely.
I'm currently using #16 and it's working for my use case (i.e. with Diff).
However as #17 reports it's not working and there are several different methods suggested setting back to active to work out which approach to go with.
Comment #25
socialnicheguru commentedComment #26
omarlopesinoPatch from comment #16 worked for me (my website was having a warning when the images where removed from media interface) , thanks!
It seems the properly moment of the code to remove the item (when it checks file if empty in order to remove).
Can this be applied to core, or it needs some help? This solves the original problem from the issue (errors when file field values are missing ).
Comment #27
kasey_mk commented#16 works for me. An AJAX error while using VBO caused my site to time out and the operation to fail; this patch fixes that problem and makes my error message go away (Warning: array_key_exists() expects parameter 2 to be array, null given in theme_image_formatter()).
Comment #28
oranges13Patch in #16 works for me, as well.
Comment #29
othermachines commentedIn my case, I have a default image set on my field. Occasionally, if an image is added and then deleted, the default image will not load and the error above appears. After applying the patch in #16, the default image loaded and the error disappeared.
Comment #30
danielvezaJust run into this again - Warning: array_key_exists() expects parameter 2 to be array, null given in theme_image_formatter().
Patch in 16 still applies and works well. Stops the error. Any particular reason this has made no progress in 5 years?
I'm happy to mark this RTBC - Seems 6 peolpe now have passes and are using this patch.
Comment #31
Rob C commentedHas been in my makefile for more than half a decade. Good question.
Comment #32
wolfshine commentedSubscribing this issue
Comment #33
mustanggb commentedComment #34
othermachines commentedJust confirming that the patch in #16 still applies against 7.x-dev.
Comment #35
mcdruid commentedIt'd be great to have a test for this.
Comment #36
mustanggb commentedComment #37
joseph.olstadNeeds tests. I don't think this occurs when file_entity is enabled but I could be mistaken.
Comment #38
mustanggb commentedComment #39
loopy1492 commentedThis patch worked for me, though it has moved down to line 187.
Comment #40
poker10 commentedI have created a test which demonstrates the warning/error (in PHP 8 it throws a TypeError, so maybe it is also a PHP 8 compatibility issue). The problem can arise in two scenarios where the file/image is being displayed:
1. System is loading file/image which has empty FID in the field_data... table
2. System is loading file/image which has FID in the field_data... table which is not present in file_managed table
Keep in mind that to trigger the error the field cache needs to be cleared, because if the file/image is loaded for the first time, it is saved in field cache and deletion afterwards does not cause Drupal to load the file again, instead it is loading data from cache_field.
Adding test only patch and the original patch from #16 with the test, which should pass. I think the approach from #16 is the correct one, as it fixes two problems at once - if this problem happens on an image field and also if this happens on a file field. Also it is safe to do this unset, as we have done something similar in #1443158: file_field_presave assumes that a file object has been loaded.
According to this and also the fact that lot of people confirmed that #16 is working I think this can be set as RTBC and commited (if the testbot will be happy).
Comment #42
poker10 commentedTestbot is happy and the test failures are present.
Comment #43
poker10 commentedI have unintentionally switched the status to RTBC. Patch was slightly modified - new test was added, so reverting the status change.
Comment #44
mcdruid commentedTest looks great and confirms that #16 fixes the main issue as described. Thanks!
I wonder if some of the earlier comments describe slightly different but related problems? Either way this should be committed.
Comment #46
poker10 commentedThanks all!
@mcdruid some patches tried to fix this more "upper", so they are quite different. But there could be some related issues - few are mentioned also in the related issues linked here.