I have a (2-arity, directional) relation defined, with two fields, including a file field. I'm using the Relation Add block to create relations. The block shows the file upload widget, but after I select the file and click the upload button, I get an error:
Warning: Invalid argument supplied for foreach() in file_field_widget_submit() (line 754 of /Applications/MAMP/localhost htdocs/commonmediainc/clpp.localhost/modules/file/file.field.inc).
Warning: array_values() [function.array-values]: The argument should be an array in file_field_widget_submit() (line 761 of /Applications/MAMP/localhost htdocs/commonmediainc/clpp.localhost/modules/file/file.field.inc).
Notice: Undefined index: field_internship_report in file_ajax_upload() (line 267 of /Applications/MAMP/localhost htdocs/commonmediainc/clpp.localhost/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 276 of /Applications/MAMP/localhost htdocs/commonmediainc/clpp.localhost/modules/file/file.module).
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | issue-1387258-relation_add-errors-on-file-upload-1387258-18.patch | 1.74 KB | mr.york |
| #17 | relation_add-errors-on-file-upload-1387258-17.patch | 1.52 KB | gaëlg |
Comments
Comment #1
pdcarto commentedAlso, if you click "create relation" with the file selected but not uploaded, the file does not get uploaded and the file field remains empty.
Comment #2
toanton commentedsame thing with Field collection
Warning: Invalid argument supplied for foreach() in file_field_widget_submit() (line 754 of /xxx/www/modules/file/file.field.inc).
Warning: array_values() [function.array-values]: The argument should be an array in file_field_widget_submit() (line 761 of /xxx/www/modules/file/file.field.inc).
Comment #3
flefle commentedSame issue here:
Warning: Invalid argument supplied for foreach() in file_field_widget_submit() (line 754 of /home/frizi/Desktop/www/eventerior/modules/file/file.field.inc).
Warning: array_values() expects parameter 1 to be array, null given in file_field_widget_submit() (line 761 of /home/frizi/Desktop/www/eventerior/modules/file/file.field.inc).
Any suggestions?
Comment #4
flefle commentedSeems that this issue has something in common with the Fields collection module. The array structure is changed which the file upload of an image field cannot handle. Thanks for suggestions.
Comment #5
kpa commentedSame issue.
The 'similar' thing with Fields Collection at http://drupal.org/node/1329856 doesnt fix it for me.
Comment #6
kpa commentedOK, fixed the issue with a quick hack to core.
Changed this in [core]/modules/files/file.field.inc (line 754):
Very simply, makes a null return from drupal_array_get_nested_value into an empty array.
I'm pretty sure that the error is actually in drupal_array_get_nested_value() in [core]/includes/common.inc. I think it should be like this?
Edit: returning an array here causes problems elsewhere. The above code addition *should* solve the problem though.
Comment #7
flefle commentedThank you for your suggestion, will try them out.
Comment #8
flefle commentedkpa: the second part provokes the following error:
Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen() (line 441 of /home/frizi/Desktop/www/eventerior/includes/unicode.inc).
Comment #9
kpa commentedYes it probably does.. The first part should solve your problem though?
The second part was more a suggestion that returning a blank array would solve the problem in this case, but clearly it's being called from elsewhere in the page load and requiring a NULL return.
Are you still having problems by just the first part?
Comment #10
mikran commentedI'm not sure whether field collection or relation add is better place for this but anyway moving out from relation to relation add for now.
Comment #11
gaëlg#6 remove the undefined index error but I still get the ones related to file_ajax_upload(). Looks like $submitted_values should be a correct non-empty array, but it fails as described there: http://drupal.org/node/1329856#comment-5211312
Maybe
$form['relation_options']['#tree']should be TRUE for the form_state array to be built as file field want it? But I guess it will break elsewhere...Comment #12
gaëlgMight be related to #745590: #managed_file element does not work when #extended not TRUE, or when ancestor element doesn't have #tree=TRUE?
Comment #13
gaëlgIn this code (file.field.inc):
Does someone know why
'#array_parents'is used to get a nested value in$form_state['values']? For me,'#array_parents'is the complete array parents list in$formvariable, and'#parents'is the one for$form_state['values'], where parents are only kept if#treeis true.I can't figure out what's wrong. Is
form_state['values']incorrectly built? Should'#array_parents'be shorter (without the first value)? Or is there a problem with file.field.inc?Comment #14
gaëlgThis might help: http://drupal.org/node/1468686#comment-6035608
Comment #15
gaëlgAdding
to the $form['relation_options'] array fixed one part of the bug for me. This is needed if only a part of the form is given as third parameter to field_attach_form.
Now I can submit the form if I don't use the ajax button "Upload". This file_ajax_upload error is another problem, discussed in several places.
Comment #16
gaëlgFor the file_ajax_upload problem, it looks like replacing
$form_state['values']['relation_type']with$form_state['input']['relation_type']in relation_add_block_form() does the trick.This is because file_ajax_upload() calls ajax_get_form() to retrieve $form and $form_state, which populates
$form_state['input']but not$form_state['values'].Comment #17
gaëlgHere's a patch including my last two comments.
Comment #18
mr.york commentedWhen we press the submit button the file wont be attached to the relation, only when the upload happens with ajax.
I've fixed some other problems in the form_submit_hook.