You are here

function _upload_form in Drupal 4

Same name and namespace in other branches
  1. 5 modules/upload/upload.module \_upload_form()
  2. 6 modules/upload/upload.module \_upload_form()
2 calls to _upload_form()
upload_form_alter in modules/upload.module
upload_js in modules/upload.module
Menu-callback for JavaScript-based uploads.

File

modules/upload.module, line 664
File-handling and attaching files to nodes.

Code

function _upload_form($node) {
  $form['#theme'] = 'upload_form_new';
  if (is_array($node->files) && count($node->files)) {
    $form['files']['#theme'] = 'upload_form_current';
    $form['files']['#tree'] = TRUE;
    foreach ($node->files as $key => $file) {
      $description = file_create_url(strpos($file->fid, 'upload') === false ? $file->filepath : file_create_filename($file->filename, file_create_path()));
      $description = "<small>" . check_plain($description) . "</small>";
      $form['files'][$key]['description'] = array(
        '#type' => 'textfield',
        '#default_value' => strlen($file->description) ? $file->description : $file->filename,
        '#maxlength' => 256,
        '#description' => $description,
      );
      $form['files'][$key]['size'] = array(
        '#type' => 'markup',
        '#value' => format_size($file->filesize),
      );
      $form['files'][$key]['remove'] = array(
        '#type' => 'checkbox',
        '#default_value' => $file->remove,
      );
      $form['files'][$key]['list'] = array(
        '#type' => 'checkbox',
        '#default_value' => $file->list,
      );

      // if the file was uploaded this page request, set value. this fixes the problem
      // formapi has recognizing new checkboxes. see comments in _upload_prepare.
      if ($_SESSION['file_current_upload'] == $file->fid) {
        $form['files'][$key]['list']['#value'] = variable_get('upload_list_default', 1);
      }
      $form['files'][$key]['filename'] = array(
        '#type' => 'value',
        '#value' => $file->filename,
      );
      $form['files'][$key]['filepath'] = array(
        '#type' => 'value',
        '#value' => $file->filepath,
      );
      $form['files'][$key]['filemime'] = array(
        '#type' => 'value',
        '#value' => $file->filemime,
      );
      $form['files'][$key]['filesize'] = array(
        '#type' => 'value',
        '#value' => $file->filesize,
      );
      $form['files'][$key]['fid'] = array(
        '#type' => 'value',
        '#value' => $file->fid,
      );
    }
  }
  if (user_access('upload files')) {

    // This div is hidden when the user uploads through JS.
    $form['new'] = array(
      '#prefix' => '<div id="attach-hide">',
      '#suffix' => '</div>',
    );
    $form['new']['upload'] = array(
      '#type' => 'file',
      '#title' => t('Attach new file'),
      '#size' => 40,
    );
    $form['new']['attach'] = array(
      '#type' => 'button',
      '#value' => t('Attach'),
      '#name' => 'attach',
      '#attributes' => array(
        'id' => 'attach',
      ),
    );

    // The class triggers the js upload behaviour.
    $form['attach'] = array(
      '#type' => 'hidden',
      '#value' => url('upload/js', NULL, NULL, TRUE),
      '#attributes' => array(
        'class' => 'upload',
      ),
    );
  }

  // Needed for JS
  $form['current']['vid'] = array(
    '#type' => 'hidden',
    '#value' => $node->vid,
  );
  return $form;
}