function download_field_formatter_view in Download 7
Same name and namespace in other branches
- 7.2 download.module \download_field_formatter_view()
Implements hook_field_formatter_view().
File
- ./
download.module, line 63 - Handles module administration and download link
Code
function download_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
case 'download_link_formatter':
foreach ($items as $delta => $item) {
if ($item['download_fields']) {
$fields = explode(';', $item['download_fields']);
$valid_file_found = FALSE;
foreach ($fields as $fieldname) {
if (isset($entity->{$fieldname})) {
foreach ($entity->{$fieldname} as $field_array) {
foreach ($field_array as $file) {
if (file_valid_uri($file['uri'])) {
$valid_file_found = TRUE;
break;
}
}
}
}
}
if ($valid_file_found) {
$element[$delta] = array(
'#theme' => 'link',
'#text' => $item['download_label'],
'#path' => 'download/' . $entity->nid . '-' . $delta . '.zip',
'#options' => array(
'attributes' => array(),
'html' => FALSE,
),
);
}
}
}
break;
}
return $element;
}