You are here

function pm_email_notify_form_user_profile_form_alter in Privatemsg 7.2

Implements hook_form_FORM_ID_alter().

File

pm_email_notify/pm_email_notify.module, line 324
Notifies users about new Private Messages via Email.

Code

function pm_email_notify_form_user_profile_form_alter(&$form, &$form_state) {
  if ($form['#user_category'] == 'account') {
    if (privatemsg_user_access('reveal e-mail address when sending messages')) {
      $form['privatemsg']['pm_show_sender_mail'] = array(
        '#type' => 'checkbox',
        '#title' => t('Show my email address'),
        '#description' => t('Use my private email address as a sender for notification mails to users I have sent private messages to. If unchecked, the notification will be sent by a generic account.'),
        '#default_value' => _pm_email_notify_show_sender($form['#user']->uid),
        '#access' => privatemsg_user_access('reveal e-mail address when sending messages'),
      );
    }
    if (privatemsg_user_access('read privatemsg')) {
      if (privatemsg_user_access('set privatemsg e-mail notification level')) {
        $form['privatemsg']['pm_email_notify_level'] = array(
          '#type' => 'radios',
          '#title' => t('Send me an e-mail notification...'),
          '#options' => array(
            PM_EMAIL_NOTIFY_LEVEL_DISABLED => t('Never.'),
            PM_EMAIL_NOTIFY_LEVEL_THREAD => t('Only for a new conversation'),
            PM_EMAIL_NOTIFY_LEVEL_UNREAD_ONCE => t("Only once for a conversation until I've read the messages"),
            PM_EMAIL_NOTIFY_LEVEL_ALL => t('Every time I receive a message'),
          ),
          '#default_value' => _pm_email_notify_user_level($form['#user']->uid),
        );
      }
      else {

        // If the user does not have permissions to customize the notification
        // level, allow him to opt out of email notifications if they are not
        // disabled by default.
        $is_enabled = _pm_email_notify_user_level();
        $form['privatemsg']['pm_email_notify_level'] = array(
          '#type' => 'checkbox',
          '#title' => t('Receive email notification for incoming private messages'),
          '#return_value' => variable_get('privatemsg_setting_email_notify_level', PM_EMAIL_NOTIFY_LEVEL_ALL),
          '#default_value' => $is_enabled ? _pm_email_notify_user_level($form['#user']->uid) : PM_EMAIL_NOTIFY_LEVEL_DISABLED,
          '#access' => (bool) $is_enabled,
        );
      }
      $form['privatemsg']['pm_email_only_user'] = array(
        '#type' => 'checkbox',
        '#title' => t("Don't send me e-mail notifications for mass messages."),
        '#default_value' => _pm_email_notify_only_user($form['#user']->uid),
        '#access' => privatemsg_user_access('change privatemsg e-mail notification for indirect messages'),
      );
    }
  }
}