You are here

function filefield_file_edit_value in FileField 6.2

Custom value callback for file edit widgets, so that we don't need to rely on a tree structure but can assemble the file to our likings.

1 string reference to 'filefield_file_edit_value'
filefield_elements in ./filefield.module
Implementation of hook_elements().

File

./filefield.widget.inc, line 544
FileField: Defines a CCK file field type.

Code

function filefield_file_edit_value($element, $edit = FALSE) {
  $file = $element['#default_value'];
  if (!is_array($edit)) {
    return $file;
  }

  // Form API is being mean to us and doesn't include the 'list' value
  // for checkboxes if the checkbox is disabled (0), only if it's enabled (1).
  // That means we need to go the extra mile.
  $list = isset($element['flags']['list']) ? !empty($edit['flags']['list']) : $file['list'];
  $file_fixed_properties = array(
    'list' => $list,
    'delete' => 0,
    'fid' => $file['fid'],
    'uid' => $file['uid'],
    'status' => $file['status'],
    'filename' => $file['filename'],
    'filepath' => $file['filepath'],
    'filemime' => $file['filemime'],
    'filesize' => $file['filesize'],
    'timestamp' => $file['timestamp'],
  );
  if (is_array($edit['edit'])) {
    $file = array_merge($file, $edit['edit']);
  }
  $file = array_merge($file, $file_fixed_properties);

  // Also merge in other values that might come from other child form elements,
  // like the '_weight' property that CCK adds to this field.
  unset($edit['flags']);
  unset($edit['edit']);
  $file = array_merge($edit, $file);
  return $file;
}