function attachment_links_render_formatter in Attachment Links 7
Helper to the theme function: Renders AL field formatters.
2 calls to attachment_links_render_formatter()
- theme_attachment_links_formatter_attachment_links_newest in ./
attachment_links.field-formatters.inc - Theme function to generate 'AL: Newest' field formatter.
- theme_attachment_links_formatter_attachment_links_preferred in ./
attachment_links.field-formatters.inc - Theme function to generate 'AL: Preferred' field formatter.
File
- ./
attachment_links.field-formatters.inc, line 78 - Field formatters for attachment_links module
Code
function attachment_links_render_formatter($node, $type = 'preferred') {
drupal_add_css(drupal_get_path('module', 'attachment_links') . '/attachment-links.base.css');
$types = array(
'preferred' => '',
'newest' => '/newest',
);
$file_field_name = variable_get('attachment_links_selection_' . $node->type, 0);
if ($file_field_name) {
$file_field = field_info_field($file_field_name);
$files = field_get_items('node', $node, $file_field['field_name']);
// If this is a 'newest' file, re-order array to sort by newest upload
if ($files && $type == 'newest') {
$files = _attachment_links_array_sort($files, 'timestamp', SORT_DESC);
}
// Format the data
$file = reset($files);
$filesize = $file['filesize'];
$fileparts = explode('.', $file['filename']);
$fileext = strtoupper(array_pop($fileparts));
$filename = implode('.', $fileparts);
$fileclass = str_replace('/', '-', $file['filemime']);
// Final output
$formatted = '<span class="al-file ' . $fileclass . '">';
$formatted .= l($filename, "node/{$node->nid}/attachment" . $types[$type]) . ' [' . $fileext . ', ' . ceil($filesize / 1000) . 'kB]';
$formatted .= '</span>';
return $formatted;
}
return 'attachment_links can\'t format this field with the current settings :(';
}