When you have multi-valued filefield, and pressing "Add more button" in node composing form, a new value of filefield appears without initialization of default values. For example, if you get your filefield "list by default", any added values to filefield are "not listed" by default.

I've fixed default values in multi-valued file field. There are two source of this bug I found:
1. Incorrect defaults initialization at filefield_widget() function (filefield.module.patch)
2. Incorrect data thrown to filefield_widget_value() function by the CCK's handler (In fact, I'm not sure that my fix don't brake something in CCK. But I've done some tests and everything seems to be fine)

Comments

neochief’s picture

dopry’s picture

Status: Needs review » Fixed

the filefield side has been cleaned up... :) thanks for noting the oversight!

Moonshine’s picture

Status: Fixed » Active

Hmm... I think the patch applied from this issue has caused a problem. $items[$delta] can still come in empty, and is now no longer set to an array of any kind as it was previously:

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/filefield/f...

This leads to warnings:

warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/html/drupal/drupal-6.6/sites/all/modules/filefield/filefield.module on line 296.
warning: array_merge() [function.array-merge]: Argument #1 is not an array in /var/www/html/drupal/drupal-6.6/sites/all/modules/filefield/filefield_widget.inc on line 173.

If nothing else maybe we should add something like this back:

if (empty($items[$delta])) $items[$delta] = _filefield_default_value($field);
Moonshine’s picture

Version: 6.x-3.0-alpha5 » 6.x-3.x-dev
Assigned: Unassigned » Moonshine
Status: Active » Needs review
StatusFileSize
new467 bytes

Patch included...

dopry’s picture

@Moonshine: in what cases does items come in empty?

amitaibu’s picture

StatusFileSize
new510 bytes

It comes empty when doing this

  if (!$edit) {
    $file =  field_file_load($element['#default_value']['fid']);
    $item = $element['#default_value'];
  }

However the $element['#default_value'] is empty.

Moonshine's patch seems to work, re-rolled according to coding standards.

pwolanin’s picture

Can observe the bug this way:

add 2x filefields to a node type (one of them using the image widget). Without the patch I get 2 array merge errors when going to edit a node of that type:

warning: array_merge() [function.array-merge]: Argument #1 is not an array in /filefield/filefield_widget.inc on line 173.

plus the same eorror for line 297

Patch above eliminates the error message.

dopry’s picture

Status: Needs review » Fixed

I figured out another fix... the code base has changed a bit since the last patches were posted.

Status: Fixed » Closed (fixed)

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