You are here

function privatemsg_attachments_form_privatemsg_new_alter in Privatemsg 6.2

Implements hook_form_FORM_ID_alter().

1 call to privatemsg_attachments_form_privatemsg_new_alter()
privatemsg_attachments_form_privatemsg_form_reply_alter in privatemsg_attachments/privatemsg_attachments.module
Implements hook_form_FORM_ID_alter().

File

privatemsg_attachments/privatemsg_attachments.module, line 32
Allows users to add attachments to messages

Code

function privatemsg_attachments_form_privatemsg_new_alter(&$form, &$form_state) {
  if (user_access('upload private message attachments')) {
    $form['attachments'] = array(
      '#type' => 'fieldset',
      '#access' => user_access('upload private message attachments'),
      '#title' => t('File attachments'),
      '#collapsible' => TRUE,
      '#collapsed' => empty($form['#privatemsg_message']['files']),
      '#description' => t('Changes made to the attachments are not permanent until you send this message.'),
      '#prefix' => '<div class="attachments">',
      '#suffix' => '</div>',
      '#weight' => 1,
    );

    // Wrapper for fieldset contents (used by ahah.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();
    $dir = variable_get('privatemsg_attachments_upload_dir', '');
    if (!empty($dir) && $dir[0] !== '/') {
      $dir = '/' . $dir;
    }
    $path .= $dir;

    // 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 attachment fieldset in the module\'s administration settings may not have been properly configured.');
      if (user_access('administer privatemsg settings')) {
        $form['attachments']['#description'] .= ' ' . t('Please visit the <a href="@admin-file-system">Private Messages module configuration page</a>.', array(
          '@admin-file-system' => url('admin/settings/messages'),
        ));
      }
      else {
        $form['attachments']['#description'] .= ' ' . t('Please contact the site administrator.');
      }
    }
    else {
      $files = array();
      if (!empty($form_state['storage']['files'])) {
        $files = $form_state['storage']['files'];
        $form['attachments']['#collapsed'] = FALSE;
      }
      $form['attachments']['wrapper'] += _privatemsg_attachments_form($files);

      // Execute submit function as validate, to have it executed before
      // $form_state['validate_built_message'] is created.
      array_unshift($form['#validate'], '_privatemsg_attachments_upload_submit');
      $form['#attributes']['enctype'] = 'multipart/form-data';
    }
  }
}