You are here

function _upload_element_expand in Upload element 6

Our #process callback to expand the control.

1 string reference to '_upload_element_expand'
upload_element_elements in ./upload_element.module
Implementation of hook_elements().

File

./upload_element.module, line 126
A module that provides two new elements to the FAPI for file handling.

Code

function _upload_element_expand($element, $edit, &$form_state, $complete_form) {

  // We need this to parse the form cache for image preview
  // and ajax functions.
  $element['#build_id'] = $complete_form['#build_id'];

  // A form rebuild changes the form build id
  if (isset($form_state['#' . $element['#name']])) {
    if ($form_state['#' . $element['#name']] != $element['#build_id']) {
      if (isset($_SESSION['files']['upload_element'][$form_state['#' . $element['#name']]])) {
        $_SESSION['files']['upload_element'][$element['#build_id']] = $_SESSION['files']['upload_element'][$form_state['#' . $element['#name']]];
        unset($_SESSION['files']['upload_element'][$form_state['#' . $element['#name']]]);
        $form_state['rebuild'] = TRUE;
      }
    }
  }
  $form_state['#' . $element['#name']] = $element['#build_id'];
  if (!count($complete_form['#post'])) {
    $_SESSION['files']['upload_element'][$element['#build_id']][$element['#name'] . '_default'] = array_key_exists('#value', $element) ? $element['#value'] : $element['#default_value'];
  }

  // move things around a bit
  $children = element_children($element);
  $element[$element['#name'] . '_custom_elements'] = array();
  foreach ($children as $child) {
    $element[$element['#name'] . '_custom_elements'][$child] = $element[$child];
    unset($element[$child]);
  }
  $element[$element['#name'] . '_upload_element_file'] = array(
    '#type' => 'file',
    '#size' => $element['#size'] ? $element['#size'] : 40,
    '#name' => 'files[' . $element['#name'] . ']',
    '#id' => form_clean_id("edit-file-{$element['#name']}"),
    '#description' => theme('upload_element_file_description', $element),
  );
  $element[$element['#name'] . '_upload_element_ahah'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
    '#name' => $element['#name'] . '-upload-element',
    '#prefix' => '<div class="form-item">',
    '#suffix' => '</div>',
    '#ahah' => array(
      'path' => 'upload_element_js/' . $element['#build_id'] . '/' . $complete_form['form_id']['#value'] . '/' . $element['#name'],
      'wrapper' => $element['#id'] . '-ahah-wrapper',
      'method' => 'replace',
      'progress' => array(
        'type' => 'bar',
        'message' => t('Please wait...'),
      ),
      'effect' => 'none',
    ),
  );
  return $element;
}