function mediafield_field_prepare_view in D7 Media 7.4
Same name and namespace in other branches
- 7.2 modules/mediafield/mediafield.module \mediafield_field_prepare_view()
- 7.3 modules/mediafield/mediafield.module \mediafield_field_prepare_view()
Implements hook_field_prepare_view().
File
- modules/
mediafield/ mediafield.module, line 151 - Provide a "Multimedia asset" field.
Code
function mediafield_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
// Collect all file IDs that need loading.
$fids = array();
foreach ($entities as $id => $entity) {
// Load the files from the files table.
foreach ($items[$id] as $delta => $item) {
if (!empty($item['fid'])) {
$fids[] = $item['fid'];
}
}
}
// Load the file entities.
$files = file_load_multiple($fids);
// Add the loaded file entities to the field item array.
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($files[$item['fid']])) {
unset($items[$id][$delta]);
}
else {
$items[$id][$delta]['file'] = $files[$item['fid']];
}
}
}
}