function video_default_widget_settings_validate in Video 6.5
Same name and namespace in other branches
- 6.4 video_widget.inc \video_default_widget_settings_validate()
Element specific validation for video default value.
1 string reference to 'video_default_widget_settings_validate'
File
- ./
video_widget.inc, line 452 - Common Video module widget functions
Code
function video_default_widget_settings_validate($element, &$form_state) {
// Verify the destination exists
$destination = video_thumb_path();
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;
}
$oldthumb = $form_state['values']['default_video_thumb'];
// We save the upload here because we can't know the correct path until the file is saved.
$newthumb = file_save_upload('default_video_thumb_upload', array(
'file_validate_is_image' => array(),
), $destination);
// Delete the current file if there is a new one or the delete_default_video_thumbnail checkbox is checked
if (!empty($oldthumb['fid']) && ($newthumb || !empty($form_state['values']['delete_default_video_thumbnail']))) {
if (file_delete(file_create_path($oldthumb['filepath']))) {
db_query('DELETE FROM {files} WHERE fid=%d', $oldthumb['fid']);
}
$form_state['values']['default_video_thumb'] = array();
}
if ($newthumb) {
// Make the file permanent and store it in the form.
file_set_status($newthumb, FILE_STATUS_PERMANENT);
$newthumb->timestamp = time();
$form_state['values']['default_video_thumb'] = (array) $newthumb;
}
}