function download_count_field_formatter_view in Download Count 7.3
Implements hook_field_formatter_view().
File
- includes/
download_count.field.inc, line 24 - Implement a file field formatter that includes download count.
Code
function download_count_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$entity_info = entity_get_info($entity_type);
$access = user_access('view download counts');
foreach ($items as $delta => $item) {
if ($access) {
$item['downloads'] = db_query("SELECT COUNT(fid) from {download_count} where fid = :fid AND type = :type AND id = :id", array(
':fid' => $item['fid'],
':type' => $entity_type,
':id' => $entity->{$entity_info['entity keys']['id']},
))
->fetchField();
}
$element[$delta] = array(
'#theme' => !$access ? 'file_link' : 'download_count_file_field_formatter',
'#file' => (object) $item,
);
}
return $element;
}