Hi,

I want to create a custom format for the filefield, to just display the associated icon for the file that has been uploaded. I cannot see a replacement token for the file icon.. can anyone help me out? I think I might need to do an Advanced formatter, but i'm not a coder, so need a little help if possible.

Thanks
Rich

Comments

rich_lang’s picture

For anyone else struggling with this, my quick fix was to assign a class to the [filefield-view] token in my custom formatter HTML code (basic mode), and then use CSS to target the class and hide the 'a' link.

Code was: .filefield-view-icon-only .filefield-file a {display:none; visibility:hidden;}

It would still be nice to have a token for the icon though :-)

7h3kk1d’s picture

Is there any way to have the icon link to the file?

rich_lang’s picture

You could try wrapping a href tag around the icons replacement token, and set the link with another replacement token.

zJoriz’s picture

Did you find anything out in the meantime? Did you find a valid replacement token for the file icon?

Same problem here: I've seen the icon get called successfully by strings of php code inserted in a custom php field for Views:

$value = $data->[NODE ID HERE]; //relevant fid
if ($value != NULL){
      $file = field_file_load($value);
      //print_r($file); //prints out various rows for file array
      $filepath = base_path().$file['filepath'];
      $filename = $file['filename'];
      $icon = theme('filefield_icon', $file);
      $filesize = format_size($file['filesize']);   
      $link = "<a href='$filepath' target='_blank'>$filename</a>";

      print "<div class='file-attachment'>".$icon." ".$link."</div>";
}

But I'm not skilled enough to use advanced view for custom formatter.

The thing I want is basically quite simple: I wish to use the link exactly like it appears in normal filefield output, but with a target="_blank" added to the link. After way too much hours of searching fiddling I got the view field working. After another half a day I've ended up with a custom formatter field for the full node, which does the same. However, the icon is missing.

funkytraffic’s picture

  $path = $element['#item']['filepath'];
  $url = file_create_url($path);
  $icon = theme('filefield_icon', $element['#item']);
  $filename = !empty($element['#item']['data']['description']) ? $element['#item']['data']['description'] : $element['#item']['filename'];

  // Output.
  return '<span class="filefield filefield-file icon">'.l( $icon, $url, array('attributes' => array('target' => '_blank', 'title' => $filename),'html' => TRUE,)) .'</span>';
 

This might help.

funkytraffic’s picture

<?php
  $path = $element['#item']['filepath'];
  $url = file_create_url($path);
  $icon = theme('filefield_icon', $element['#item']);
  $filename = !empty($element['#item']['data']['description']) ? $element['#item']['data']['description'] : $element['#item']['filename'];

  // Output.
  return '<span class="filefield filefield-file icon">'.l( $icon, $url, array('attributes' => array('target' => '_blank', 'title' => $filename),'html' => TRUE,)) .'</span>';
  ?>

For 6 this might help, for 7 I donnot know.

Deciphered’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

I am no longer supporting any Drupal 6 modules, as such I am marking this as closed.

However, I am open to taking on co-maintainers, if you wish to do so contact me via me D.o contact form.