By default Drupal 7 output attached files: file name and size of attachment I heed to add an additional column with Download link to every attached file.
In my template.php i have added:
// Override attachments files in case of use table formatter
function bkisk_file_formatter_table($variables) {
$header = array(t('Attachment'), t('Download'), t('Size')); // added Download column
$rows = array();
foreach ($variables['items'] as $delta => $item) {
$rows[] = array(
theme('file_link', array('file' => (object) $item)),
theme('file_link', array('file' => (object) $item)), // ???
format_size($item['filesize']),
);
}
return empty($rows) ? '' : theme('table', array('header' => $header, 'rows' => $rows));
}
function bkisk_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
$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'] = 'откроется в новой вкладке';
$options['attributes']['target'] = '_blank'; // add _blank param
}
return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
}
i have http://i.stack.imgur.com/W76kW.png
i need to do like this http://i.stack.imgur.com/cmKMj.png
ill be very appreciated for your help!
l('Download', $item['uri']),
it creates path to file domain.com/public%3A//files/23/ustav_gup_sk_bki_sk_no795_ot_16.06.14.pdf – user34535 Aug 13 '14 at 11:39