默认情况下,Drupal 7输出附加文件:文件名和附件大小 我注意添加一个带有下载链接的附加列到每个附加文件。
在我的 template.php 中,我添加了:
// 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>';
}
目前,我有:
我需要这样做:
非常感谢所有帮助。
答案 0 :(得分:0)
通过添加到file_link()函数构造
来部分解决任务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
$options_download['attributes']['title'] = 'Скачать ' . "[" . $link_text . "]";
$options_download['attributes']['download'] = '';
}
return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span><br /><br />' .
'<span class="file-download">' . l('Download', $url, $options_download) . '</span>';
}