You are here

function comment_notify_form_alter in Comment Notify 7

Same name and namespace in other branches
  1. 5.2 comment_notify.module \comment_notify_form_alter()
  2. 5 comment_notify.module \comment_notify_form_alter()
  3. 6 comment_notify.module \comment_notify_form_alter()

Implements hook_form_alter().

File

./comment_notify.module, line 309
This module provides comment follow-up e-mail notification for anonymous and registered users.

Code

function comment_notify_form_alter(&$form, &$form_state, $form_id) {
  module_load_include('inc', 'comment_notify', 'comment_notify');
  if (!($form_id == 'user_register_form' || $form_id == 'user_profile_form')) {
    return;
  }
  elseif ($form['#user_category'] != 'account') {
    return;
  }
  $user = $form['#user'];
  if (!empty($user->comment_notify_settings)) {
    $node_notify = $user->comment_notify_settings->node_notify;
    $comment_notify = $user->comment_notify_settings->comment_notify;
  }
  $form['comment_notify_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Comment follow-up notification settings'),
    '#weight' => 4,
    '#collapsible' => TRUE,
  );

  // Only show the node followup UI if the user has permission to create nodes.
  $nodes = FALSE;
  foreach (node_type_get_names() as $type => $name) {
    if (node_access('create', $type)) {
      $nodes = TRUE;
      break;
    }
  }
  if (user_access('administer nodes') || $nodes) {
    $form['comment_notify_settings']['node_notify'] = array(
      '#type' => 'checkbox',
      '#title' => t('Receive content follow-up notification e-mails'),
      '#default_value' => isset($node_notify) ? $node_notify : comment_notify_variable_registry_get('node_notify_default_mailalert'),
      '#description' => t('Check this box to receive an e-mail notification for follow-ups on your content. You can not disable notifications for individual threads.'),
    );
  }
  else {
    $form['comment_notify_settings']['node_notify'] = array(
      '#type' => 'hidden',
      '#value' => COMMENT_NOTIFY_DISABLED,
    );
  }
  $available_options[COMMENT_NOTIFY_DISABLED] = t('No notifications');
  $available_options += _comment_notify_options();
  $form['comment_notify_settings']['comment_notify'] = array(
    '#type' => 'select',
    '#title' => t('Receive comment follow-up notification e-mails'),
    '#default_value' => isset($comment_notify) ? array(
      $comment_notify,
    ) : array(
      comment_notify_variable_registry_get('default_registered_mailalert'),
    ),
    '#options' => $available_options,
    '#description' => t("Check this box to receive e-mail notification for follow-up comments to comments you posted. You can later disable this on a post-by-post basis... so if you leave this to YES, you can still disable follow-up notifications for comments you don't want follow-up mails anymore - i.e. for very popular posts."),
  );
  return $form;

  // Construct the user form.
}