You are here

function filefield_nginx_progress_element_process in FileField Nginx Progress 7

Same name and namespace in other branches
  1. 7.2 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'
filefield_nginx_progress_element_info in ./filefield_nginx_progress.module
Implementation of hook_element_info().

File

./filefield_nginx_progress.module, line 68
Adds upload progress functionality to FileFields on the nginx webserver.

Code

function filefield_nginx_progress_element_process($element, &$form_state, $form) {

  // Generate 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
  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;
}