This is a tricky one.
I'm having two profile types on the user registration form, including an image field. Now, whenever I upload or delete a file, the following two error messages appear:
Warning: Invalid argument supplied for foreach() in file_field_widget_form() (Zeile 464 von /var/www/web/modules/file/file.field.inc).
Warning: array_values() expects parameter 1 to be array, null given in file_field_widget_form() (Zeile 473 von /var/www/web/modules/file/file.field.inc).
However, the upload or delete works well.
Tracking the bug down, I found out that file_field_widget_form() is being called several times on each Ajax reload (and as well on the initial page display). And the more profile types there are used on the form, the more often file_field_widget_form() gets called, once wih the complete data and another time not.
The bug initially stem from profile2_form_user_register_form_alter(), where profile2_attach_form() is being called once per profile type and every time it is called it goes through the whole array of profiles.
Including patch fixes that behaviour, making sure profile2_attach_form() is called only once after all profile types are ready processed. Now the errors are gone.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 1095490-errors-user-registration-form.patch | 730 bytes | ericbroder |
| #2 | 1095490-errors-user-registration-form-D7.patch | 730 bytes | ericbroder |
| #1 | 1095490_Fix_errors_on-user_registration.patch | 1.12 KB | pancho |
Comments
Comment #1
panchoHere's the patch...
Comment #2
ericbroder commentedHi Pancho, the format of your patch is a little junked up, here's a cleaner version. Maybe it'll test better.
Comment #3
ericbroder commentedTrying again...
Comment #4
ericbroder commentedPatch looks good to me. Warning message goes away, don't see any loss of functionality. Code changes seem pretty minor too.
Comment #5
ericbroder commentedCould still use additional testing to be safe.
Comment #6
fagothe patch doesn't look right, we need to attach the form of each profile. Anyway, I think there is a general problem with images/files if modules embed the field API form not at the $form root, like profile2 and field-collection do.
Also see #1187010: Image field malfunctioning on embedded field collection form..
Comment #7
yched commentedThat was an issue I had with file fields when working on the core patch that allowed widgets within nested forms : see #942310-120: Field form cannot be attached more than once.
I opened #977898: Filefield upload widget broken in combofield for core once the main patch got in. I'd tend to think that this thread and #1187010: Image field malfunctioning on embedded field collection form. are both dupes of that core issue, but :
When he worked on the "embedded" widget for field_collection, @casey posted a patch that allegedly fixed the issue with file uploads : #977890-25: Display collection fields within entity form (subform/embedded).
I'd be surprised that this can be fixed on the contrib side, and I'm not sure what his fix was back then (filefields are still broken with the code that eventually got committed in that issue), nor whether it was a correct fix, but according to #1187010-5: Image field malfunctioning on embedded field collection form., it at least worked to some extent for the field_collection widget.
I'll try to ping @casey, see if he remembers what his findings were on the topic.
Comment #8
casey commentedHi, got your mail. Looking at current code of field collection and my patches there are some differences.
In this patch I fixed file fields:
http://drupal.org/node/977890#comment-4233662
At least the value callback I added there is missing. I don't have time to look into it much further. Good luck.
Comment #9
fagoIs there still an issue? Please, re-open if so with the latest modules.
Comment #10
dready2011 commentedSubscribing. Thanks for the patch, solved my problems with an image field on the profile 2 page on user registration!
Comment #11
Leeteq commentedIs this still an issue (is the patch still relevant)?