Hi,

Came across a really subtle bug for you to look at. I don't quite believe it myself at first, so I'd like to get your opinion.

In filefield_field_settings_form(), your #options arrays are using keys 0 and 1, and this messes up your computation of #default_value.

If $field['list_default'] is 0, then $field['list_default'] == '' evaluates to true.
If $field['list_default'] is '0', then $field['list_default'] == '' evaluates to false.

So, if $field['list_default'] had been set to 0, then in your form, you set the #default_value of $form['list_default'] to 1, when it should be the other value.

As an illustration, stick the following code in a devel.module Execute PHP block:

$field['list_default'] = 0;
print $field['list_default'] == '' ? 1 : (int) $field['list_default'];
print "\n";
$field['list_default'] = '0';
print $field['list_default'] == '' ? 1 : (int) $field['list_default'];
print "\n";
print 0 == '';
print "\n";
print '0' == '';
print "\n";

And see what you get.

This is what I get:

1
0
1
Files: 
CommentFileSizeAuthor
#1 filefield_305476.patch2.02 KBdrewish

Comments

Status:Active» Needs review
StatusFileSize
new2.02 KB

how about doing it this way?

Hi,

Yep, your patch fixes the issue.

FYI, this issue doesn't arise when someone is adding a filefield to a cck type, because when a user submits the form at .../admin/content/node-type/*/fields/field_file, cck saves the values as strings instead of integers ie. '0' instead of 0.

It only occurred for me because I did a cck type export and then an import. The exported type definition had list_default and other values as 0 instead of '0'.

Anyway, thank you for your help.

Status:Needs review» Reviewed & tested by the community

Status:Reviewed & tested by the community» Fixed

thanks, committed to HEAD.

Status:Fixed» Closed (fixed)

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