Am I missing something? As I have noticed, when field is displayed in a node, there should be an icon next to it, based on mime type?
I have created ico folder and put some icons in it. How to display those icons when viewing a node, not just editing it?

Thanks in advance.

Comments

mrtoner’s picture

Bump. As far as I can tell, theme_filefield_icon() is not called when viewing a node, only when editing a node.

jpetso’s picture

That's right, theme_filefield() is called when you view a node, and to get mimetype icons there you have to override theme_filefield() by theming. I think I already closed an issue asking for the exact same thing, you could search for it in the list of closed issues - if I'm correct there was even a code snippet in there. Let's leave this open, maybe we can enable icons by default when we ship an icon set with filefield.

mrtoner’s picture

If I'm not mistaken, that was http://drupal.org/node/185902#comment-617408.

I've found a fairly decent source for open source icons at http://www.iconfinder.net/.

Don

encho’s picture

Man u rock! Thanks for the second link as well, being looking for it.

mrtoner’s picture

An example of overriding theme_filefield(), using the info in that link, would be:

function phptemplate_filefield ($file) {
  if (user_access('view filefield uploads') && is_file($file['filepath']) && $file['list']) {
    $path = ($file['fid'] == 'upload')
            ? file_create_filename($file['filename'], file_create_path($field['widget']['file_path']))
            : $file['filepath'];

    $url = file_create_url($path);
    $name = $file['filename'];
    $desc = $file['description'];
    return theme('filefield_icon', $file) . '<a href="'. check_url($url) .'">'. check_plain($desc) .'</a>';
  }
  return '';
}
jpetso’s picture

Title: Icons not displayed? » [docs] Displaying icons also in the node view
Component: Miscellaneous » Documentation

Thanks for the snippet, mrtoner. I would assume this support request can be regarded as "fixed", although I'm sure there'll be duplicate issues if I close it. Maybe something for the module documentation? I think I'll reassign this to the "Documentation" component... if someone wants to write up a few explanatory sentences and test the above snippet, here's your chance to contribute.

Rob T’s picture

Thanks, mrtoner. This snippet came in handy.

dopry’s picture

Title: [docs] Displaying icons also in the node view » Add icons to default filefield formatters.
Version: 5.x-2.2 » 6.x-3.x-dev
Category: support » feature

Add file type icons to theme_filefield.

jpetso’s picture

Status: Active » Needs review
StatusFileSize
new8.47 KB

It's getting time that I can justify my maintainer status again by doing a bit of work.

Find attached a patch that uses the shipped icons, complete with fallbacks (not *just* as flexible as the desktops with their "is also of mimetype xyz" subclassings, but still). The patch in its current form still hardcodes the "protocons" icon set without providing an opportunity to switch, and I also couldn't figure out how to let the icon div actually float left like the CSS file says it should. Using Firefox 3, my Firebug is currently out of order :(

If someone can fix the latter, this patch is not far from being ready. Works already, and using a temporary hack of replacing the div with a span it looked pretty nice already. @dopry: please review the function names in particular, I'm not quite sure with those.

jpetso’s picture

StatusFileSize
new8.47 KB

Er, oops. Never rename functions *after* you test the patch. Corrected patch now attached.

miles28’s picture

Adding the filesize (KB):

function phptemplate_filefield ($file) {
if (user_access('view filefield uploads') && is_file($file['filepath']) && $file['list']) {
$path = ($file['fid'] == 'upload')
? file_create_filename($file['filename'], file_create_path($field['widget']['file_path']))
: $file['filepath'];

$url = file_create_url($path);
$name = $file['filename'];
$desc = $file['description'];
return theme('filefield_icon', $file) . ''. check_plain($desc) .'' . ' [' . (format_size($file['filesize'])) . ']';
}
return '';
}

jpetso’s picture

This issue is about icons and should not include additional extensions like the filesize. Please create a proper patch and open a separate issue for that feature request. (Also, use the t() function for concatenating any user visible strings.)

dopry’s picture

Status: Needs review » Reviewed & tested by the community

jpetso, feel free to commit this as long as you've tested it and it works...

jpetso’s picture

Status: Reviewed & tested by the community » Fixed

Committed with a lot more testing and a few bugfixes. Filefield now shows icons by default both on the edit form and on the node view, and more importantly, it uses the fd.o icon naming specification compliant names and fallback algorithms. No backwards compatibility has been provided for the previous extension-based selection of icons, so if you have customized your icon set then you need to adapt it to the new naming scheme.

Yeah, you are gonna like it. I do!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.