You are here

function upload_form_alter in Drupal 5

Same name and namespace in other branches
  1. 4 modules/upload.module \upload_form_alter()
  2. 6 modules/upload/upload.module \upload_form_alter()

File

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

Code

function upload_form_alter($form_id, &$form) {
  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
    $form['workflow']['upload'] = array(
      '#type' => 'radios',
      '#title' => t('Attachments'),
      '#default_value' => variable_get('upload_' . $form['#node_type']->type, 1),
      '#options' => array(
        t('Disabled'),
        t('Enabled'),
      ),
    );
  }
  if (isset($form['type'])) {
    $node = $form['#node'];
    if ($form['type']['#value'] . '_node_form' == $form_id && variable_get("upload_{$node->type}", TRUE)) {
      drupal_add_js('misc/progress.js');
      drupal_add_js('misc/upload.js');

      // Attachments fieldset
      $form['attachments'] = array(
        '#type' => 'fieldset',
        '#access' => user_access('upload files'),
        '#title' => t('File attachments'),
        '#collapsible' => TRUE,
        '#collapsed' => empty($node->files),
        '#description' => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
        '#prefix' => '<div class="attachments">',
        '#suffix' => '</div>',
        '#weight' => 30,
      );

      // Wrapper for fieldset contents (used by upload JS).
      $form['attachments']['wrapper'] = array(
        '#prefix' => '<div id="attach-wrapper">',
        '#suffix' => '</div>',
      );

      // Make sure necessary directories for upload.module exist and are
      // writable before displaying the attachment form.
      $path = file_directory_path();
      $temp = file_directory_temp();

      // Note: pass by reference
      if (!file_check_directory($path, FILE_CREATE_DIRECTORY) || !file_check_directory($temp, FILE_CREATE_DIRECTORY)) {
        $form['attachments']['#description'] = t('File attachments are disabled. The file directories have not been properly configured.');
        if (user_access('administer site configuration')) {
          $form['attachments']['#description'] .= ' ' . t('Please visit the <a href="@admin-file-system">file system configuration page</a>.', array(
            '@admin-file-system' => url('admin/settings/file-system'),
          ));
        }
        else {
          $form['attachments']['#description'] .= ' ' . t('Please contact the site administrator.');
        }
      }
      else {
        $form['attachments']['wrapper'] += _upload_form($node);
        $form['#attributes']['enctype'] = 'multipart/form-data';
      }
    }
  }
}