function file_field_presave

Implements hook_field_presave().

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

File

drupal/modules/file/file.field.inc, line 215
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);
    }
  }
}