Taking a test drive with D7, I came across this error message:
Notice: Undefined index: display_field in file_field_widget_form() (line 497 of G:\www\d7\modules\file\file.field.inc).
Before that, I did roughly the following:
- installed Drupal 7 (checked out today) with the normal installation profile
- renamed the 'article' content type to 'blog'
- created another content type, 'photo'
- added the (already existing) image field called 'image' to the photo content type
- set the image field settings on 'photo' to unlimited values, public files, enable alt field
- went to /node/add/blog, where the error message occurred
The error also occurs on /node/add/photo.
I think this qualifies as critical, please correct me if I'm wrong.
Comments
Comment #1
benoit.borrel commentedHi,
Indeed,
$elements['#display_field'] = $field['settings']['display_field'];generated the error because $field['settings'] has default values...The debug backtrace is:
#0 file_field_widget_form()
#1 image_field_widget_form()
#2 field_default_form()
#3 _field_invoke()
#4 _field_invoke_default()
#5 field_attach_form()
#6 node_form()
#7 call_user_func_array()
#8 drupal_retrieve_form()
#9 drupal_build_form()
#10 drupal_get_form()
#11 node_add()
#12 call_user_func_array()
#13 menu_execute_active_handler()
However, I wasn't able to track down where $field['settings']['display_field'] was supposed to be set...
Anyone?
Comment #2
marcvangendThe thing is, image field used to be just a formatter for file field, but now it's officially on it's own. That said, it still re-uses file field functions quite a lot. File field adds a value for the display_field setting in file_field_info(), but image_field_info() does not have that setting. When rendering the node form, image field re-uses file_field_widget_form(), but that function is not prepared for the possibility that display_field is not set.
An easy fix would be to check if
isset($field['settings']['display_field'])around line 513 (used to be 497) of file_field_widget_form(), but think we should look at this code a little longer.It seems as if the display_field setting on the widget settings form has no effect on the node form at all...[edit] Sorry, my mistake, the 'display' checkbox does work. By the way, if filefield has this 'display' checkbox, shouldn't image field have one as well? [/edit]
Comment #3
yrocq commentedThe problem is that the function file_field_widget_form try to use the "display_default", which isn't available in the image field context. The best solution I found is to check if the option is set before using it.
#d7csmtl
Comment #5
marcvangendYes, I came to the same conclusion. However I think it is safer to set the default value (0) when $field['settings']['display_field'] is not set. See patch.
Comment #6
marcvangendtest bot, have a go!
Comment #7
yrocq commentedYeah, I first chose this solution but I was wondering if it was a good idea to set a variable we won't use. However, you're right, it may be more secure.
Comment #8
marcvangendAfter a night's sleep, I'm still not sure if the patch in #5 is the best solution.
Technically it works fine of course, but it feels slightly hackish right to hard-code a default value in file_field_widget_form() while default values should actually be set in hook_field_info.
On the other hand, it wouldn't be right either to add
'display_field' => 0,to image_field_info() just for the sake of fixing a bug, while the image field doesn't even have a display field.Meanwhile the question remains if image field should have a display checkbox just like file field does... Any thoughts?
Comment #9
yched commentedMarked #719640: Undefined index: display_field in file_field_widget_form as duplicate.
That's very true.
- image fields don't have a 'display field' setting,
- image widget defers to file widget to do the actual work
- file widget assumes a 'display field' setting
So I think it's the job of image_field_widget_form() to add the missing $field['settings']['display field'] value before handing the job to file_field_widget_form()
Comment #10
marcvangendyched, thanks for your input, I completely agree. New patch attached.
Comment #11
marcvangendTests passed and the error is gone. RTBC AFAIC.
Comment #12
yched commentedLooks good. Thanks !
Comment #13
dries commentedCommitted to CVS HEAD. Thanks.
Comment #15
LTech commentedI'm using 7.9 and so the patch is already part of my code but I still get the error :
Notice: Undefined index: display_field in file_field_widget_value() (line 579 of /home//modules/file/file.field.inc).
I get the error when I click 'upload' but I haven't added a file to upload.
How can I get rid of the error?
Should I open a new issue?
Comment #16
jim_at_miramontes commentedHi -- Don't know if this is still an issue for you, but I bumped up against this as well. http://drupal.org/node/1430934#comment-5725004 has a patch that worked for me...
Comment #17
doitDave commentedError still or again occures with image field in 7.20.
Notice: Undefined index: display_field in file_field_widget_value() (Line 579 of /home/x/y/z/modules/file/file.field.inc).
Didn't notice it before, probably reoccurs after the image token changes in 7.20.
Comment #18
tregismoreira commentedError still here too (in 7.22). It's occurs after enabled the Autoupload module.
Any idea?
Comment #19
dcam commentedhttp://drupal.org/node/1427826 contains instructions for updating the issue summary with the summary template.
The summary may need to be updated with information from comments.
Comment #20
David_Rothstein commentedThe last several comments seem to refer to an entirely different PHP notice that is already being handled in #1430934: Notice: Undefined index: display_field in file_field_widget_value() (line 582 of /module/file/file.field.inc)..
Reclosing.
Comment #21
fabianx commentedChanging status to duplicate
Comment #22
fabianx commentedActually fixed was correct