You are here

function image_fupload_form_alter in Image FUpload 6.2

Implementation of hook_form_alter() registry.

File

./image_fupload.module, line 80

Code

function image_fupload_form_alter(&$form, $form_state, $form_id) {
  global $user;

  // examine whether it's a new image type & the user wants to have flash
  if ($form_id == "image_node_form" && !isset($form['#node']->nid) && arg(3) != "noflash") {

    // Some needed JS & CSS - Files to be included
    drupal_add_js(drupal_get_path('module', 'image_fupload') . '/swfupload/swfupload.js', 'module');
    drupal_add_js(drupal_get_path('module', 'image_fupload') . '/swfupload/swfupload.queue.js', 'module');
    drupal_add_js(drupal_get_path('module', 'image_fupload') . '/swfupload/fileprogress.js', 'module');
    drupal_add_js(drupal_get_path('module', 'image_fupload') . '/swfupload/handlers.js', 'module');
    drupal_add_js(theme('swfupload_settings', base_path() . drupal_get_path('module', 'image_fupload'), url('fupload/flash'), round(variable_get('image_max_upload_size', 800)), $user->sid, 100), 'inline');
    unset($form['title'], $form['rebuild_images'], $form['buttons']['preview']);

    //don't need this, title will be generated later using filepath
    isset($form['taxonomy']) ? $form['taxonomy']['#weight'] = -8 : "";

    //adds ablility to sort better in this case
    $form['message'] = array(
      '#value' => '<div id="jsstatus"></div>',
      '#weight' => -7,
    );
    $form['image'] = array(
      '#type' => 'fieldset',
      '#title' => t('Images'),
      '#weight' => -6,
      '#attributes' => array(
        'class' => 'flash',
        'id' => 'fsUploadProgress',
      ),
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
    );
    $form['upload_info'] = array(
      '#value' => t('0 Files uploaded.'),
      '#prefix' => '<div id="divStatus">',
      '#suffix' => '</div>',
      '#weight' => -5,
    );

    // Drupal 6 Bug: can't use "normal" buttons, only submit buttons are possible => workaround
    $form['upload_buttons'] = array(
      '#prefix' => '<div>',
      '#value' => '<input type="button" value="' . t('Select Images') . '" onclick="swfu.selectFiles()" /> <input id="btnCancel" type="button" value="' . t('Cancel All Uploads') . '" onclick="swfu.cancelQueue();" disabled="disabled" /> ',
      '#suffix' => '</div>',
      '#weight' => -4,
    );
    $form['upload_buttons']['node_create'] = array(
      '#type' => 'submit',
      '#value' => t('Process queued images'),
      '#weight' => -3,
      '#ahah' => array(
        'path' => 'fupload/js',
        'event' => 'click',
        'method' => 'replace',
        'wrapper' => 'jsstatus',
        'progress' => array(
          'type' => 'bar',
          'message' => t('Images in queue are processed...'),
        ),
      ),
    );
    $form['upload_buttons']['delete_queue'] = array(
      '#type' => 'submit',
      '#value' => t('Delete queued images'),
      '#weight' => -2,
      '#ahah' => array(
        'path' => 'fupload/js/deletequeue',
        'event' => 'click',
        'method' => 'append',
        'wrapper' => 'jsstatus',
      ),
    );
    $form['buttons']['submit'] = array(
      '#value' => '<input type="button" value="' . t('Upload Images') . '" id="startuploadbutton" onclick="startUploadProcess()" />',
      '#weight' => 5,
      '#submit' => array(
        'node_form_submit',
      ),
    );
    $form['#redirect'] = FALSE;

    // Important that $_POST is not empty after browser submit
    $form['#submit'][0] = '_image_node_form_submit';

    // use our emulated version instead of original one in image.module
  }
}