function filefield_widget_value in FileField 6.3
The #value_callback for the filefield_widget type element.
1 string reference to 'filefield_widget_value'
- filefield_elements in ./
filefield.module - Implementation of hook_elements().
File
- ./
filefield_widget.inc, line 213 - This file contains CCK widget related functionality.
Code
function filefield_widget_value($element, $edit = FALSE) {
if (!$edit) {
$file = field_file_load($element['#default_value']['fid']);
$item = $element['#default_value'];
}
else {
$item = $edit;
$field = content_fields($element['#field_name'], $element['#type_name']);
// Uploads take priority over value of fid text field.
if ($fid = filefield_save_upload($element)) {
$item['fid'] = $fid;
}
elseif (isset($element['#filefield_value_callback'])) {
foreach ($element['#filefield_value_callback'] as $callback) {
$callback($element, $item);
}
}
// Load file if the FID has changed so that it can be saved by CCK.
$file = isset($item['fid']) ? field_file_load($item['fid']) : NULL;
// If the file entry doesn't exist, don't save anything.
if (empty($file)) {
$item = array();
$file = array();
}
// Checkboxes loose their value when empty.
// If the list field is present make sure its unchecked value is saved.
if (!empty($field['list_field']) && empty($edit['list'])) {
$item['list'] = 0;
}
}
// Merge file and item data so it is available to all widgets.
if (isset($item['data']) && isset($file['data'])) {
$file['data'] = array_merge($item['data'], $file['data']);
}
$item = array_merge($item, $file);
return $item;
}