Drupal : How to enable FileField Image to Print images with Print Module HTML/PDF
Hello folks
Well if you use the module ImageField + FileField to include images in your custom node content types and if you need to print your custom content type, you will notice that all images are rendered as files with links in HTML and PDF formats, off course you want to include images to get a close print representation of your node.
The problem is the module print for some reason don't process the imagefield theme function, but uses the filefield theme function instead.
The solution is overwrite the filefield theme function and detect if our field contain an image in order to do the proper display. Check the code below.
/**
* Theme function for the 'generic' single file formatter.
*/
function email_institute_filefield_file($file) {
// Views may call this function with a NULL value, return an empty string.
if (empty($file['fid'])) {
return '';
}
$path = $file['filepath'];
$url = file_create_url($path);
$options = array(
'attributes' => array(
'type' => $file['filemime'] . '; length=' . $file['filesize'],
),
);
// Use the description as the link text if available.
if (empty($file['data']['description'])) {
$link_text = $file['filename'];
}
else {
$link_text = $file['data']['description'];
$options['attributes']['title'] = $file['filename'];
}
if(strstr($file['filemime'],'image')) {
$image_files++;
$image = theme('imagecache','propnormal',$path);
return '
' . $image .'
';
} else {
$icon = theme('filefield_icon', $file);
return '
'. $icon . l($link_text, $url, $options) .'
';
}
}
Enjoy it
enzo







