7.x file.field.inc theme_file_formatter_table($variables)

Returns HTML for a file attachments table.

Parameters

$variables: An associative array containing:

  • items: An array of file attachments.

Related topics

File

modules/file/file.field.inc, line 1020
Field module functionality for the File module.

Code

function theme_file_formatter_table($variables) {
  $header = array(
    t('Attachment'),
    t('Size'),
  );
  $rows = array();
  foreach ($variables['items'] as $delta => $item) {
    $rows[] = array(
      theme('file_link', array(
        'file' => (object) $item,
      )),
      format_size($item['filesize']),
    );
  }
  return empty($rows) ? '' : theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
}

Comments

rar’s picture

Print_r($item) results in (with real data replaced)

[fid] => integer
[display] => 1
[description] => Text
[uid] => integer
[filename] => Text_name_of_file
[uri] => public://Text_name_of_file
[filemime] => mime_type (e.g. application/msword)
[filesize] => integer
[status] => 1
[timestamp] => 0

Timestamp is 0 if you've upgraded from Drupal 6 to Drupal 7.

openstep’s picture

I already added the upload date like so https://drupal.org/node/1711636#comment-7550401
But can someone tell me how to extend this table with for example file description?

thank you

miller2676’s picture

Add this to your rows array:

format_string($item['description']),