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.

Comments

pancho’s picture

Status: Active » Needs review
StatusFileSize
new1.12 KB

Here's the patch...

ericbroder’s picture

Hi Pancho, the format of your patch is a little junked up, here's a cleaner version. Maybe it'll test better.

ericbroder’s picture

StatusFileSize
new730 bytes

Trying again...

ericbroder’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good to me. Warning message goes away, don't see any loss of functionality. Code changes seem pretty minor too.

ericbroder’s picture

Status: Reviewed & tested by the community » Needs review

Could still use additional testing to be safe.

fago’s picture

Title: Errors on user registration form » Problems with files/images in the user registration form
Status: Needs review » Needs work

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

yched’s picture

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

casey’s picture

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

fago’s picture

Status: Needs work » Postponed (maintainer needs more info)

Is there still an issue? Please, re-open if so with the latest modules.

dready2011’s picture

Subscribing. Thanks for the patch, solved my problems with an image field on the profile 2 page on user registration!

Leeteq’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active

Is this still an issue (is the patch still relevant)?