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
Comment | File | Size | Author |
---|---|---|---|
#1 | filefield_305476.patch | 2.02 KB | drewish |
Comments
Comment #1
drewish CreditAttribution: drewish commentedhow about doing it this way?
Comment #2
bengtan CreditAttribution: bengtan commentedHi,
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.
Comment #3
bengtan CreditAttribution: bengtan commentedComment #4
drewish CreditAttribution: drewish commentedthanks, committed to HEAD.
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.