(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;
CommentFileSizeAuthor
#1 1337362-2.patch516 bytesgood_man

Comments

good_man’s picture

Status: Active » Needs review
StatusFileSize
new516 bytes

I think with no items, we should return from the function directly, without even going into the switch.

spoit’s picture

Even 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 :)

good_man’s picture

The return in the beginning saves Drupal from the overhead of switch, hence a little better performance :)

shyamala’s picture

Status: Needs review » Closed (duplicate)

Duplicate of issue: http://drupal.org/node/1146088, need to move Drupal 7 patch to the old issue.