function filefield_nginx_progress_element_process in FileField Nginx Progress 7.2
Same name and namespace in other branches
- 7 filefield_nginx_progress.module \filefield_nginx_progress_element_process()
A #process callback to extend the file_widget element type.
To get the field working with nginx upload progress, we need to enable the progress bar and modify the ahah paths to work with the nginx redirection.
1 string reference to 'filefield_nginx_progress_element_process'
File
- ./
filefield_nginx_progress.module, line 83 - filefield_nginx_progress.module @author Ben Osman <dev@smoothify.com> António P. P. Almeida <appa@perusio.net> @date Sun Oct 21 14:31:03 2012
Code
function filefield_nginx_progress_element_process($element, &$form_state, $form) {
// Generate a random upload progress key.
$upload_progress_key = mt_rand();
// Nginx really wants us to send a get value, but form_expand_ahah doesn't
// allow query strings in paths. The work around is to add the progress id
// into the path and to rewrite at the nginx level to the required url.
$element['upload_button']['#ajax']['path'] .= '/x-progress-id:' . $upload_progress_key;
// Add the upload key to the form, in a manner compatible with the existing
// javascript
$element['UPLOAD_IDENTIFIER'] = array(
'#type' => 'hidden',
'#value' => $upload_progress_key,
'#attributes' => array(
'class' => array(
'file-progress',
),
),
);
// Unset this as a precaution in the unlikely event that apc upload progress
// is enabled in php.ini.
if (isset($element['APC_UPLOAD_PROGRESS'])) {
unset($element['APC_UPLOAD_PROGRESS']);
}
// Enable the progress bar.
$element['upload_button']['#ajax']['progress']['type'] = 'bar';
// Modify the upload progress callback to use our own menu callback.
$element['upload_button']['#ajax']['progress']['path'] = 'filefield_nginx_progress/' . $upload_progress_key;
return $element;
}