Commit d44a7ce7 authored by Florian Suter's avatar Florian Suter Committed by Federico Calo
Browse files

Issue #2890031 by flosuter: Show file description instead of filename on link

parent 15503c05
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ class TrackDaFilesFormatter extends FileFormatterBase {
    		$url = track_da_files_create_url($file->getFileUri());
    		$options['attributes']['type'] = $mime_type . '; length=' . $filesize;
      $options['query']['file'] = '1';
      $item = $file->_referringItem;

		  if (isset($type)) {
		    $options['query']['type'] = $type;
@@ -48,7 +49,7 @@ class TrackDaFilesFormatter extends FileFormatterBase {
		    $options['query']['id'] = $id;
		  }

		  $text = isset($file->description) ? $file->description : $filename;
		  $text = isset($item->description) ? $item->description : $filename;
      $link = \Drupal::l($text, Url::fromUri($url, $options));

      $elements[$delta] = array(
@@ -61,12 +62,12 @@ class TrackDaFilesFormatter extends FileFormatterBase {
      ); 

      // Pass field item attributes to the theme function.
      if (isset($file->_attributes)) {
      if (isset($item->_attributes)) {
        $elements[$delta] += array('#attributes' => array());
        $elements[$delta]['#attributes'] += $file->_attributes;
        $elements[$delta]['#attributes'] += $item->_attributes;
        // Unset field item attributes since they have been included in the
        // formatter output and should not be rendered in the field template.
        unset($file->_attributes);
        unset($item->_attributes);
      }
    }
    if (!empty($elements)) {