function file_field_presave

7.x file.field.inc file_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items)

Implements hook_field_presave().

1 call to file_field_presave()
image_field_presave in drupal-7.x/modules/image/image.field.inc
Implements hook_field_presave().

File

drupal-7.x/modules/file/file.field.inc, line 214
Field module functionality for the File module.

Code

function file_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
  // Make sure that each file which will be saved with this object has a
  // permanent status, so that it will not be removed when temporary files are
  // cleaned up.
  foreach ($items as $delta => $item) {
    if (empty($item['fid'])) {
      unset($items[$delta]);
      continue;
    }
    $file = file_load($item['fid']);
    if (empty($file)) {
      unset($items[$delta]);
      continue;
    }
    if (!$file->status) {
      $file->status = FILE_STATUS_PERMANENT;
      file_save($file);
    }
  }
}