function download_field_formatter_view in Download 7.2
Same name and namespace in other branches
- 7 download.module \download_field_formatter_view()
Implements hook_field_formatter_view().
File
- ./
download.module, line 97 - 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':
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
foreach ($items as $delta => $item) {
if ($item['download_fields']) {
$fields = explode(';', $item['download_fields']);
$valid_file_found = FALSE;
$fname = NULL;
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;
$fname = $field['field_name'];
break;
}
}
}
}
}
if ($valid_file_found) {
$element[$delta] = array(
'#theme' => 'link',
'#text' => $item['download_label'],
'#path' => 'download/' . $bundle . '/' . $entity_type . '-' . $fname . '-' . $id . '-' . $delta,
'#options' => array(
'attributes' => array(),
'html' => FALSE,
),
);
}
}
}
break;
}
return $element;
}