You are here

function field_file_save in FileField 6.2

Same name and namespace in other branches
  1. 6.3 field_file.inc \field_file_save()

Update an field item file. Delete marked items if neccessary and set new items as permamant.

Parameters

$node: Node object this file is be associated with.

$file: File to be inserted, passed by reference since fid should be attached.

Return value

array

1 call to field_file_save()
filefield_field in ./filefield.module
Implementation of CCK's hook_field().

File

./field_file.inc, line 105
Common functionality for file handling CCK field modules.

Code

function field_file_save($node, &$file) {

  // If this item is marked for deletion.
  if (!empty($file['delete'])) {

    // If we're creating a new revision, return an empty array so CCK will
    // remove the item.
    if (!empty($node->old_vid)) {
      return array();
    }

    // Otherwise delete the file and return an empty array.
    if (field_file_delete($file)) {
      return array();
    }
  }

  // Cast to object since core functions use objects.
  $file = (object) $file;

  // Set permanent status on files if unset.
  if (empty($file->status)) {
    file_set_status($file, FILE_STATUS_PERMANENT);
  }

  // Let modules update their additional file properties too.
  foreach (module_implements('file_update') as $module) {
    $function = $module . '_file_update';
    $function($file);
  }
  _field_file_cache($file);

  // update the cache, in case the file has changed
  $file = (array) $file;
  return $file;
}