function privatemsg_form_alter

7-1 privatemsg.module privatemsg_form_alter(&$form, &$form_state, $form_id)
7-2 privatemsg.module privatemsg_form_alter(&$form, &$form_state, $form_id)

Implements hook_form_alter().

File

./privatemsg.module, line 1339
Allows users to send private messages to other users.

Code

function privatemsg_form_alter(&$form, &$form_state, $form_id) {
  if (($form_id == 'user_register_form' || $form_id == 'user_profile_form') && $form['#user_category'] == 'account') {

    // Create array to be able to merge in fieldset and avoid overwriting
    // already added options.
    if (!isset($form['privatemsg'])) {
      $form['privatemsg'] = array();
    }

    // Always create the fieldset in case other modules want to add
    // Privatemsg-related settings through hook_form_alter(). If it's still
    // empty after the build process, the after build function will remove it.
    $form['privatemsg'] += array(
      '#type' => 'fieldset',
      '#title' => t('Private messages'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#weight' => 10,
      '#after_build' => array('privatemsg_account_fieldset_remove_if_empty'),
    );

    // We have to use user_access() because privatemsg_user_access() would
    // return FALSE when privatemsg is disabled.
    if ((user_access('write privatemsg') || user_access('read privatemsg')) && user_access('allow disabling privatemsg') && privatemsg_allow_disable($form['#user'])) {
      $form['privatemsg']['pm_enable'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable private messages'),
        '#default_value' => !privatemsg_is_disabled($form['#user']),
        '#description' => t('Disabling private messages prevents you from sending or receiving messages from other users.'),
        '#weight' => -10,
      );
    }
  }
}