File size on View

portulaca - July 5, 2009 - 19:03
Project:FileField
Version:6.x-3.1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I can see the sile size when in Edit mode of a node where Filefield is present, is there a way to show it in View mode too?

#1

quicksketch - July 5, 2009 - 20:16

Yes, you can override the theme_filefield_item().

- Find theme_filefield_item() in filefield.formatter.inc.
- Copy the entire function to your theme's template.php file, rename it to [your_theme_name]_filefield_item().
- Add the file size to the output.

<?php
function [yourtheme]_filefield_item($file, $field) {
  if (
filefield_view_access($field['field_name']) && filefield_file_listed($file, $field)) {
    return
theme('filefield_file', $file) . format_size($file['filesize']);
  }
  return
'';
}
?>

#2

portulaca - July 5, 2009 - 20:39

wow speedy reply :)

I tested this on my local drupal and it works! Thank you!

#3

quicksketch - July 5, 2009 - 22:41
Status:active» fixed

Nice. FileField provides several different levels at which you can intercept the output, this one seemed most appropriate for what you're trying to do. You can do the same thing with any other theme_* functions if this one doesn't do exactly what you want.

#4

System Message - July 19, 2009 - 22:50
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.