function THEMENAME_file_link($variables) {
$file = $variables['file'];
$icon_directory = $variables['icon_directory'];
$url = file_create_url($file->uri);
$icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
// Set options as per anchor format described at
// http://microformats.org/wiki/file-format-examples
$options = array(
'attributes' => array(
'type' => $file->filemime . '; length=' . $file->filesize,
),
);
// Use the description as the link text if available.
if (empty($file->description)) {
$link_text = $file->filename;
}
else {
$link_text = $file->description;
$options['attributes']['title'] = check_plain($file->filename);
}
//open files of particular mime types in new window
$new_window_mimetypes = array('application/pdf','text/plain','application/msword','image/jpeg','image/png');
if (in_array($file->filemime, $new_window_mimetypes)) {
$options['attributes']['target'] = '_blank';
}
return '' . $icon . ' ' . l($link_text, $url, $options) . '';
}
Contact Us
- Post a Public Question
- Email Us
- Live Chat!
-
Drupal 8 Themes »
Thanks so much for your detailed answer. You guys are the best.
Eder Miranda
UNODATA, March 2017I’m marking this as solved. You guys are awesome. I’ll never go anywhere else for my themes. Your service and support have been awesome and this was literally above and beyond. Thanks!
Dan White
President, Nexxus Cloud LLC., April 2015You are great! Problem solved. Thank you so much for nice and helpful support.
Schoonheid in pixels, July 2016
All is good now.
Thanks for your excellent support!David Cardinal
Cardinal Photo, April 2015Find us