You are here

function subscriptions_content_form_comment_form_alter in Subscriptions 6

Same name and namespace in other branches
  1. 7 subscriptions_content.module \subscriptions_content_form_comment_form_alter()
  2. 2.0.x subscriptions_content/subscriptions_content.module \subscriptions_content_form_comment_form_alter()

Implementation of hook_form_alter().

Add the Send Subscriptions Notifications checkbox to the Administration Options fieldset on the comment edit form.

File

./subscriptions_content.module, line 495
Subscriptions to content events

Code

function subscriptions_content_form_comment_form_alter(&$form, &$form_state) {
  $is_update = isset($form['admin']);
  $is_unpublished = $is_update ? $form['admin']['status']['#default_value'] : !user_access('post comments without approval');
  if (user_access('administer comments')) {
    $tr = 't';

    // create the Administration fieldset if it doesn't exist:
    if (!isset($form['admin'])) {
      $form['admin'] = array(
        '#type' => 'fieldset',
        '#title' => $tr('Administration'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#weight' => -2,
      );
    }
    $form['admin']['subscriptions_notify'] = array(
      '#type' => 'checkbox',
      '#title' => t('Send subscriptions notifications'),
      '#weight' => -1,
    );
    $node = node_load($form['nid']['#value']);
    $default_workflow = subscriptions_content_get_default_workflow($node->type);
    if ($is_update && $is_unpublished) {
      $form['admin']['subscriptions_notify']['#description'] = t('Subscriptions notifications are not sent for unpublished comments (except to users who have the %administer_comments permission), but when you change !Status to %Published, Subscriptions will send out "new" notifications, unless you suppress this here.', array(
        '%administer_comments' => $tr('administer comments'),
        '!Status' => $tr('Status'),
        '%Published' => $tr('Published'),
      ));
      $form['admin']['subscriptions_notify']['#default_value'] = in_array('c_unpub', $default_workflow);
    }
    elseif ($is_unpublished) {
      $form['admin']['subscriptions_notify']['#description'] = t('Subscriptions notifications are not sent for unpublished comments, except to users who have the %administer_comments permission, and you can even suppress the latter here.', array(
        '%administer_comments' => $tr('administer comments'),
      ));
      $form['admin']['subscriptions_notify']['#default_value'] = in_array('c_new', $default_workflow);
    }
    else {

      // published, new or update
      $form['admin']['subscriptions_notify']['#description'] = t('You can suppress sending subscriptions notifications here; this option is not saved.');
      $form['admin']['subscriptions_notify']['#default_value'] = in_array($is_update ? 'c_pub' : 'c_new', $default_workflow);
    }
  }
}