function _uploadfield_widget_settings_default_validate in Video 6.3
Element specific validation for uploadfield default value.
Validated in a separate function from uploadfield_field() to get access to the $form_state variable.
1 string reference to '_uploadfield_widget_settings_default_validate'
- uploadfield_widget_settings_form in types/
uploadfield/ uploadfield_widget.inc - Implementation of CCK's hook_widget_settings($op = 'form').
File
- types/
uploadfield/ uploadfield_widget.inc, line 109 - uploadfield widget hooks and callbacks.
Code
function _uploadfield_widget_settings_default_validate($element, &$form_state) {
// Verify the destination exists
$destination = file_directory_path() . '/video_thumb';
if (!field_file_check_directory($destination, FILE_CREATE_DIRECTORY)) {
form_set_error('default_video_thumb', t('The default image could not be uploaded. The destination %destination does not exist or is not writable by the server.', array(
'%destination' => dirname($destination),
)));
return;
}
$validators = array(
'file_validate_is_image' => array(),
);
// We save the upload here because we can't know the correct path until the file is saved.
if (!($file = file_save_upload('default_video_thumb_upload', $validators, $destination))) {
// No upload to save we hope... or file_save_upload() reported an error on its own.
return;
}
// Remove old image (if any) & clean up database.
$old_default = $form_state['values']['default_video_thumb'];
if (!empty($old_default['fid'])) {
if (file_delete(file_create_path($old_default['filepath']))) {
db_query('DELETE FROM {files} WHERE fid=%d', $old_default['fid']);
}
}
// Make the file permanent and store it in the form.
file_set_status($file, FILE_STATUS_PERMANENT);
$file->timestamp = time();
$form_state['values']['default_video_thumb'] = (array) $file;
}