You are here

function theme_track_da_files_file_link in Track da files 8

Same name and namespace in other branches
  1. 7 includes/track_da_files_formatter.inc \theme_track_da_files_file_link()

Returns HTML for a link to a file.

Parameters

array $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.
1 theme call to theme_track_da_files_file_link()
theme_track_da_files_file_formatter_table in includes/track_da_files_formatter.inc
Returns HTML for a file attachments table.

File

includes/track_da_files_formatter.inc, line 30
This file contains the specialized field formatters.

Code

function theme_track_da_files_file_link($variables) {
  $file_field_links_show_enabled = \Drupal::config('track_da_files.settings')
    ->get('file_field_links_show_enabled');
  $output = '';
  $file = $variables['file'];
  $options = array(
    'attributes' => $variables['attributes'],
  );

  // Set options as per anchor format described at
  // http://microformats.org/wiki/file-format-examples
  $url = track_da_files_create_url($file
    ->getFileUri());

  // Set options as per anchor format described at
  // http://microformats.org/wiki/file-format-examples
  $options['attributes']['type'] = $file
    ->getMimeType() . '; length=' . $file
    ->getSize();

  // Use the description as the link text if available.
  if (empty($variables['description'])) {

    //$link_text = $file->getFilename();
  }
  else {
    $link_text = $variables['description'];
    $options['attributes']['title'] = check_plain($file
      ->getFilename());
  }
  $file_icon = array(
    '#theme' => 'file_icon',
    '#file' => $file,
    '#icon_directory' => $variables['icon_directory'],
  );
  $options['query']['file'] = '1';
  if (isset($file->type)) {
    $options['query']['type'] = $file->type;
  }
  if (isset($file->id)) {
    $options['query']['id'] = $file->id;
  }
  $output = '<span class="file">' . drupal_render($file_icon) . ' ' . l($link_text, $url, $options) . '</span>';
  if (isset($file->displays) && ($file->displays > 0 && isset($track_da_files_file_field_links_show_enabled))) {
    $output .= '<span class="file-displayed-counter">' . format_plural($file->displays, 'displayed 1 time', 'displayed @count times') . '</span>';
  }
  return $output;
}