You are here

function imagefield_file_update in ImageField 5.2

Same name and namespace in other branches
  1. 5 imagefield.module \imagefield_file_update()

Update the file record if necessary.

Parameters

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

$file: A single CCK image field item to be updated.

$field: The field definition for this image field.

1 call to imagefield_file_update()
imagefield_field in ./imagefield.module
Implementation of hook_field().

File

./imagefield.module, line 261
Defines an image field type. imagefield uses content.module to store the fid, and the drupal files table to store the actual file data.

Code

function imagefield_file_update($node, &$file, $field) {
  $file = (array) $file;
  if ($file['flags']['delete'] == true) {

    // don't delete files if we're creating new revisions, but still return an
    // empty array...
    if (empty($node->old_vid)) {
      _imagefield_file_delete($file, $field['field_name']);
    }
    if ($field['multiple']) {

      // If multiple, return an empty array so the file entry is removed from
      // the content field table.
      $file = array();
    }
    else {

      // If not multiple, empty the array so it's updated to 0 in the main
      // content type table. If we don't do this, a reference to a non existent
      // file (fid) will be left on the content type table.
      foreach ($file as $key => $value) {
        $file[$key] = NULL;
      }
    }
    return $file;
  }
  if ($file['fid'] == 'upload') {
    return imagefield_file_insert($node, $file, $field);
  }
  else {

    // empty files without fid.
    if ($file['fid'] == 0) {
      $file = array();
    }

    // if fid is not numeric here we should complain.
    // else we update the file table.
  }
  return $file;
}