Filefield seems to handle empty field values in inconsistent ways - sometimes returning an empty array...
$node->field_xyz[0] = NULL
... sometimes returning an array populated with empty values ...
$node->field_xyz[0] = array(fid => NULL, list => NULL, data => NULL,)
... and sometimes returning an array populated with default values ...
$node->field_xyz[0] = array(fid => 0, list => 1, data => 1,)
This is specifically causing problems with the Driven module: see #865388: Filefield reporting all files removed and added . The "fix" that I applied in that issue, as mentioned in comment #37, is to change line ~136 of filefield_field.inc to $items[$delta] = array('fid' => NULL, 'list' => NULL, 'data' => NULL,);. It's seems like there might be a better permanent solution to this problem though... what do you think?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | filefield-1132622-8.patch | 425 bytes | danepowell |
| #5 | filefield-1132622-5.patch | 482 bytes | danepowell |
Comments
Comment #1
arhak commentedsubscribing
Comment #2
danepowell commentedJust FYI, it seems that a more appropriate "fix" for the issue I was having is to unset
$items[$delta]at that line. At any rate...Comment #3
obrienmd commentedsubscribe
Comment #4
quicksketchSure I'd agree that handling NULL values would be a good thing. If you provide a patch I'd be happy to give it a look. Other modules can avoid this being a problem by using empty($file['fid']) as their check, since that will always work no matter if $file is NULL or if $file['fid'] is 0 or NULL.
Comment #5
danepowell commentedWell there seems to be a number of possible solutions, but this one makes the most sense to me- simply calling content_set_empty on the $items array before it is returned from filefield_field_load
Comment #6
arhak commented@#4
annoying when using foreach, the key exists and still pops up, also other functions fail (if not considered the nullified key) e.g: array_key_exists, array_diff_key, array_intersect_key, and so on
which would require an extra array_filter
@#5
if CCK takes care of this on
presaveandview(the later only when previewing)perhaps CCK should consider doing it on
loadas wellPS: how is it handled for D7?
Comment #7
arhak commented@#5 patch
trailing spaces on empty line
Comment #8
danepowell commentedSorry, no trailing space this time...
I agree that the problem seems to be that content_set_empty is never called on the load op, so we should do it manually. Maybe it would be better if CCK did this in core *shrug*. I'm just not familiar enough with CCK to say.
Comment #9
danepowell commentedThe patch in #8 should still apply to 6.x-3.10