You are here

function subscriptions_content_form_comment_form_alter in Subscriptions 7

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

Implements hook_form_alter().

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

_state

Parameters

array $form:

File

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

Code

function subscriptions_content_form_comment_form_alter(array &$form, array &$form_state) {
  $is_update = isset($form['cid']['#value']);
  $is_unpublished = $is_update ? $form['author']['status']['#default_value'] : !user_access('post comments without approval');
  if (user_access('administer comments')) {
    $tr = 't';
    $item =& $form['author']['subscriptions_notify'];
    $item['#type'] = 'item';
    $item['subscriptions_notify'] = array(
      '#type' => 'checkbox',
      '#title' => t('Send subscriptions notifications'),
    );
    $node = node_load($form['nid']['#value']);
    $default_workflow = subscriptions_content_get_default_workflow($node->type);
    if ($is_update && $is_unpublished) {
      $item['#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'),
      ));
      $item['subscriptions_notify']['#default_value'] = in_array('c_unpub', $default_workflow);
    }
    elseif ($is_unpublished) {
      $item['#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'),
      ));
      $item['subscriptions_notify']['#default_value'] = in_array('c_new', $default_workflow);
    }
    else {

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