You are here

function _upload_form in Drupal 6

Same name and namespace in other branches
  1. 4 modules/upload.module \_upload_form()
  2. 5 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 465
File-handling and attaching files to nodes.

Code

function _upload_form($node) {
  global $user;
  $form = array(
    '#theme' => 'upload_form_new',
    '#cache' => TRUE,
  );
  if (!empty($node->files) && is_array($node->files)) {
    $form['files']['#theme'] = 'upload_form_current';
    $form['files']['#tree'] = TRUE;
    foreach ($node->files as $key => $file) {
      $file = (object) $file;
      $description = file_create_url($file->filepath);
      $description = "<small>" . check_plain($description) . "</small>";
      $form['files'][$key]['description'] = array(
        '#type' => 'textfield',
        '#default_value' => !empty($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' => !empty($file->remove),
      );
      $form['files'][$key]['list'] = array(
        '#type' => 'checkbox',
        '#default_value' => $file->list,
      );
      $form['files'][$key]['weight'] = array(
        '#type' => 'weight',
        '#delta' => count($node->files),
        '#default_value' => $file->weight,
      );
      $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,
      );
      $form['files'][$key]['new'] = array(
        '#type' => 'value',
        '#value' => FALSE,
      );
    }
  }
  if (user_access('upload files')) {
    $limits = _upload_file_limits($user);
    $form['new']['#weight'] = 10;
    $form['new']['upload'] = array(
      '#type' => 'file',
      '#title' => t('Attach new file'),
      '#size' => 40,
      '#description' => ($limits['resolution'] ? t('Images are larger than %resolution will be resized. ', array(
        '%resolution' => $limits['resolution'],
      )) : '') . t('The maximum upload size is %filesize. Only files with the following extensions may be uploaded: %extensions. ', array(
        '%extensions' => $limits['extensions'],
        '%filesize' => format_size($limits['file_size']),
      )),
    );
    $form['new']['attach'] = array(
      '#type' => 'submit',
      '#value' => t('Attach'),
      '#name' => 'attach',
      '#ahah' => array(
        'path' => 'upload/js',
        'wrapper' => 'attach-wrapper',
        'progress' => array(
          'type' => 'bar',
          'message' => t('Please wait...'),
        ),
      ),
      '#submit' => array(
        'node_form_submit_build_node',
      ),
    );
  }
  return $form;
}