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

benoit.borrel’s picture

Hi,

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?

marcvangend’s picture

The 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]

yrocq’s picture

Status: Active » Needs review
StatusFileSize
new838 bytes

The 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

Status: Needs review » Needs work

The last submitted patch, 714350_fix_undefined_index.patch, failed testing.

marcvangend’s picture

StatusFileSize
new928 bytes

Yes, 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.

marcvangend’s picture

Status: Needs work » Needs review

test bot, have a go!

yrocq’s picture

Yeah, 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.

marcvangend’s picture

After 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?

yched’s picture

Marked #719640: Undefined index: display_field in file_field_widget_form as duplicate.

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.

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()

marcvangend’s picture

StatusFileSize
new870 bytes

yched, thanks for your input, I completely agree. New patch attached.

marcvangend’s picture

Tests passed and the error is gone. RTBC AFAIC.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Thanks !

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

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

LTech’s picture

I'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?

jim_at_miramontes’s picture

Hi -- 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...

doitDave’s picture

Version: 7.x-dev » 7.20
Priority: Critical » Major
Status: Closed (fixed) » Active

Error 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.

tregismoreira’s picture

Error still here too (in 7.22). It's occurs after enabled the Autoupload module.

Any idea?

dcam’s picture

http://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.

David_Rothstein’s picture

Version: 7.20 » 7.x-dev
Status: Active » Closed (fixed)

The 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.

fabianx’s picture

Changing status to duplicate

fabianx’s picture

Status: Closed (duplicate) » Fixed

Actually fixed was correct

Status: Fixed » Closed (fixed)

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