function filefield_field_update in FileField 6.3
Implementation of CCK's hook_field($op = 'update').
1 call to filefield_field_update()
- filefield_field_insert in ./
filefield_field.inc - Implementation of CCK's hook_field($op = 'insert').
File
- ./
filefield_field.inc, line 168 - FileField CCK field hooks and callbacks.
Code
function filefield_field_update($node, $field, &$items, $teaser, $page) {
// Accumulator to gather current fid to compare with the original node
// for deleting replaced files.
$curfids = array();
foreach ($items as $delta => $item) {
$items[$delta] = field_file_save($node, $item);
// Remove items from the array if they have been deleted.
if (empty($items[$delta]) || empty($items[$delta]['fid'])) {
$items[$delta] = NULL;
}
else {
$curfids[] = $items[$delta]['fid'];
}
}
// If this is a new node there are no old items to worry about.
// On new revisions, old files are always maintained in the previous revision.
if ($node->is_new || !empty($node->revision) || !empty($node->skip_filefield_delete)) {
return;
}
// Delete items from original node.
$orig = node_load($node->nid);
// If there are, figure out which ones must go.
if (!empty($orig->{$field}['field_name'])) {
foreach ($orig->{$field}['field_name'] as $oitem) {
if (isset($oitem['fid']) && !in_array($oitem['fid'], $curfids)) {
// For hook_file_references, remember that this is being deleted.
$oitem['field_name'] = $field['field_name'];
$oitem['delete_vid'] = $orig->vid;
filefield_field_delete_file($oitem, $field);
}
}
}
}