You are here

function _privatemsg_form_base_fields in Privatemsg 7.2

Same name and namespace in other branches
  1. 6.2 privatemsg.pages.inc \_privatemsg_form_base_fields()

Returns the common fields of the reply and new form.

2 calls to _privatemsg_form_base_fields()
privatemsg_form_reply in ./privatemsg.pages.inc
Form builder function; Write a reply to a thread.
privatemsg_new in ./privatemsg.pages.inc
Form builder function; Write a new private message.

File

./privatemsg.pages.inc, line 447
User menu callbacks for Privatemsg.

Code

function _privatemsg_form_base_fields($form, &$form_state) {
  global $user;
  if (isset($form_state['privatemsg_preview'])) {
    $preview_subject = '';

    // Only display subject on preview for new messages.
    if (empty($form_state['validate_built_message']->thread_id)) {
      $preview_subject = check_plain($form_state['validate_built_message']->subject);

      // If message has tokens, replace them.
      if ($form_state['validate_built_message']->has_tokens) {
        $preview_subject = privatemsg_token_replace($preview_subject, array(
          'privatemsg_message' => $form_state['validate_built_message'],
        ), array(
          'sanitize' => TRUE,
          'privatemsg-show-span' => FALSE,
        ));
      }
    }
    $form['message_header'] = array(
      '#type' => 'fieldset',
      '#title' => !empty($preview_subject) ? $preview_subject : t('Preview'),
      '#attributes' => array(
        'class' => array(
          'preview',
        ),
      ),
      '#weight' => -20,
    );
    $form['message_header']['message_preview'] = $form_state['privatemsg_preview'];
  }
  $form['author'] = array(
    '#type' => 'value',
    '#value' => $user,
  );

  // The input filter widget looses the format during preview, specify it
  // explicitly.
  if (isset($form_state['values']) && array_key_exists('format', $form_state['values'])) {
    $format = $form_state['values']['format'];
  }
  $form['body'] = array(
    '#type' => 'text_format',
    '#title' => t('Message'),
    '#rows' => 6,
    '#weight' => -3,
    '#resizable' => TRUE,
    '#format' => isset($format) ? $format : NULL,
    '#after_build' => array(
      'privatemsg_check_format_access',
    ),
  );
  if (privatemsg_user_access('use tokens in privatemsg') && module_exists('token')) {
    $form['token'] = array(
      '#type' => 'fieldset',
      '#title' => t('Token browser'),
      '#weight' => -1,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['token']['browser'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(
        'privatemsg_message',
      ),
    );
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  if (variable_get('privatemsg_display_preview_button', FALSE)) {
    $form['actions']['preview'] = array(
      '#type' => 'submit',
      '#value' => t('Preview message'),
      '#validate' => array(
        'privatemsg_new_validate',
      ),
      '#submit' => array(
        'privatemsg_new_preview',
      ),
      '#weight' => 10,
    );
  }
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send message'),
    '#weight' => 15,
    '#validate' => array(
      'privatemsg_new_validate',
    ),
    '#submit' => array(
      'privatemsg_new_submit',
    ),
  );

  // Attach field widgets.
  $message = (object) array();
  if (isset($form_state['validate_built_message'])) {
    $message = $form_state['validate_built_message'];
  }

  // If a module (e.g. OG) adds a validate or submit callback to the form in
  // field_attach_form, the form system will not add ours automatically
  // anymore. Therefore, explicitly adding them here.
  $form['#submit'] = array(
    'privatemsg_new_submit',
  );
  $form['#validate'] = array(
    'privatemsg_new_validate',
  );
  field_attach_form('privatemsg_message', $message, $form, $form_state);
  return $form;
}