function file_field_load

7.x file.field.inc file_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age)

Implements hook_field_load().

1 call to file_field_load()
image_field_load in drupal/modules/image/image.field.inc
Implements hook_field_load().

File

drupal/modules/file/file.field.inc, line 169
Field module functionality for the File module.

Code

function file_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {

  $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'];
      }
    }
  }
  $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']]);
      }
    }
  }
}