0

I have a file upload field which's format is set to generic file. It prints the following markup:

<div class="content">
  <span class="file">
    <img class="file-icon" alt="" title="application/msword" src="project/modules/file/icons/x-office-document.png">
    <a href="urltofile.doc" type="application/msword; length=22016" title="file.doc">Lorem ipsum</a>
  </span>
  <span class="file">
    ...
  </span>
</div>

But I'd rather not show the img at all, alter url text, something similar like this:

<div class="content">

  <span class="file maybe-some-custom-classes">
    <a href="urltofile.doc">$filename</a>
    <span>$description text of this field</span>
  </span>

</div>

What hooks would I have to use for this? And why is this so hard to find on the docs?!

5
  • It's a field so you'd normally alter it with field--type.tpl.php, probably field--file.tpl.php for a file field
    – Clive
    Feb 11, 2014 at 14:51
  • yeah but there is no tpl which renders <img /> in it markup specially for file fields, is there?
    – Alex
    Feb 11, 2014 at 14:54
  • Take a look here: api.drupal.org/api/drupal/modules!field!field.module/function/…
    – arrubiu
    Feb 11, 2014 at 14:59
  • Another way, without programming, is to use Custom Formatters drupal.org/project/custom_formatters
    – arrubiu
    Feb 11, 2014 at 15:00
  • @Alex not directly, but one of the contained theme functions looks to be responsible
    – Clive
    Feb 11, 2014 at 15:04

2 Answers 2

3

I'm guessing a bit here as I can't see what you have installed/configured...

The file formatter function is file_field_formatter_view(), and the only formatter which has an image attached to it runs through theme_file_link(). I would assume that's where the markup you're referring to comes from.

You can override that in your theme:

function MYTHEME_file_link($vars) {
  ...
}

Or, if you can get away without having to reproduce the function, just preprocess is:

function MYTHEME_preprocess_file_link(&$vars){ 
  ...
}
1
  • MYTHEME_file_link($vars) does the trick for me. thanks for your help
    – Alex
    Feb 11, 2014 at 15:06
0

If it is a file field, not an image field, then it shouldn't be necessary to alter the template, but instead change the display configuration. See the attached screenshots.

Or am I misunderstanding your question?

enter image description here

Which then renders like this:

enter image description here

Update: Sorry, misunderstood the question, you don't want the icon in front, didn't catch that.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.