(Hope it's not a duplicate; could not find it in the list)
When you add a file field to an entity, and select Generic File as a formatter, an instance of that entity with no attachments displays fine (nothing), when you select Table of files as a formatter, there is something returned when it shouldn't:
<div class="field field-name-field-page-attachments field-type-file field-label-hidden"><div class="field-items"></div></div>
I think the culprit is found in file.field.inc of the core file module, line 962:
case 'file_table':
// Display all values in a single element..
$element[0] = array(
'#theme' => 'file_formatter_table',
'#items' => $items,
);
break;
$element[0] will always be returned here, even if there are no files. I think it should rather be something like:
case 'file_table':
// Display all values in a single element..
if(sizeof($items) > 0) {
$element[0] = array(
'#theme' => 'file_formatter_table',
'#items' => $items,
);
}
break;
Comments
Comment #1
good_man commentedI think with no items, we should return from the function directly, without even going into the switch.
Comment #2
spoit commentedEven better, indeed. The other formatters automatically return nothing since their loop is never handled ($items is empty), but it seems safer to just return. Nice :)
Comment #3
good_man commentedThe return in the beginning saves Drupal from the overhead of switch, hence a little better performance :)
Comment #4
shyamala commentedDuplicate of issue: http://drupal.org/node/1146088, need to move Drupal 7 patch to the old issue.