function theme_file_link

7.x file.module theme_file_link($variables)

Returns HTML for a link to a file.

Parameters

$variables: An associative array containing:

  • file: A file object to which the link will be created.
  • icon_directory: (optional) A path to a directory of icons to be used for files. Defaults to the value of the "file_icon_directory" variable.

Related topics

4 theme calls to theme_file_link()
FileFieldDisplayTestCase::testNodeDisplay in drupal-7.x/modules/file/tests/file.test
Tests normal formatter display on node display.
file_field_formatter_view in drupal-7.x/modules/file/file.field.inc
Implements hook_field_formatter_view().
file_managed_file_process in drupal-7.x/modules/file/file.module
Process function to expand the managed_file element type.
theme_file_formatter_table in drupal-7.x/modules/file/file.field.inc
Returns HTML for a file attachments table.

File

drupal-7.x/modules/file/file.module, line 723
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function theme_file_link($variables) {
  $file = $variables['file'];
  $icon_directory = $variables['icon_directory'];

  $url = file_create_url($file->uri);
  $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));

  // Set options as per anchor format described at
  // http://microformats.org/wiki/file-format-examples
  $options = array(
    'attributes' => array(
      'type' => $file->filemime . '; length=' . $file->filesize,
    ),
  );

  // Use the description as the link text if available.
  if (empty($file->description)) {
    $link_text = $file->filename;
  }
  else {
    $link_text = $file->description;
    $options['attributes']['title'] = check_plain($file->filename);
  }

  return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
}