function filefield_widget_validate in FileField 6.3
An #element_validate callback for the filefield_widget field.
1 string reference to 'filefield_widget_validate'
- filefield_elements in ./
filefield.module - Implementation of hook_elements().
File
- ./
filefield_widget.inc, line 463 - This file contains CCK widget related functionality.
Code
function filefield_widget_validate(&$element, &$form_state) {
// If referencing an existing file, only allow if there are existing
// references. This prevents unmanaged files (outside of FileField) from
// being deleted if this node were to be deleted.
if (!empty($element['fid']['#value'])) {
$field = content_fields($element['#field_name'], $element['#type_name']);
if ($file = field_file_load($element['fid']['#value'])) {
$file = (object) $file;
if ($file->status == FILE_STATUS_PERMANENT) {
if (field_file_references($file) == 0 || variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE && function_exists('file_download_access') && !file_download_access($file->filepath)) {
form_error($element, t('Referencing to the file used in the %field field is not allowed.', array(
'%field' => $element['#title'],
)));
}
}
}
else {
form_error($element, t('The file referenced by the %field field does not exist.', array(
'%field' => $element['#title'],
)));
}
}
}