You are here

function _upload_form in Drupal 5

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

File

modules/upload/upload.module, line 768
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) {

      // Generate valid URL for both existing attachments and preview of new attachments (these have 'upload' in fid)
      $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(
        '#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',
      '#id' => 'attach-button',
    );

    // The class triggers the js upload behaviour.
    $form['attach-url'] = 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;
}