Implements hook_field_prepare_view().
function file_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
// Remove files specified to not be displayed.
$fids = array();
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
if (!file_field_displayed($item, $field)) {
unset($items[$id][$delta]);
}
elseif (!empty($item['fid'])) {
// Load the files from the files table.
$fids[] = $item['fid'];
}
}
// Ensure consecutive deltas.
$items[$id] = array_values($items[$id]);
}
$files = file_load_multiple($fids);
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
// If the file does not exist, mark the entire item as empty.
if (empty($item['fid']) || !isset($files[$item['fid']])) {
$items[$id][$delta] = NULL;
}
else {
$items[$id][$delta] = array_merge($item, (array) $files[$item['fid']]);
}
}
}
}