You are here

function notifications_content_form_alter in Notifications 6.3

Same name and namespace in other branches
  1. 6.4 notifications_content/notifications_content.module \notifications_content_form_alter()
  2. 6 notifications_content/notifications_content.module \notifications_content_form_alter()
  3. 6.2 notifications_content/notifications_content.module \notifications_content_form_alter()

Implementation of hook_form_alter().

File

notifications_content/notifications_content.module, line 104
Subscriptions to content events

Code

function notifications_content_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'comment_form':

      // Load the node which is possibly cached to get the node type
      $node = node_load($form['nid']['#value']);
      if (notifications_content_type_enabled($node->type)) {
        if (notifications_event_enabled('node', 'comment')) {
          _notifications_content_add_disable_field($form);
        }

        // If editing the comment, add values to remember
        if (!empty($form['cid']['#value']) && !empty($form['admin']['status'])) {
          $form['notifications_comment_status'] = array(
            '#type' => 'value',
            '#value' => $form['admin']['status']['#default_value'],
          );
        }
      }
      break;
    case 'node_type_form':
      if (isset($form['identity']['type'])) {

        // Hack for modules with different weights to add options here
        if (!isset($form['notifications'])) {
          $form['notifications'] = array();
        }
        $form['notifications'] += array(
          '#type' => 'fieldset',
          '#title' => t('Subscription settings'),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
        );
        $form['notifications']['notifications_content_type'] = array(
          '#type' => 'checkboxes',
          '#title' => t('Allowed subscription types'),
          '#default_value' => notifications_content_type_enabled($form['#node_type']->type),
          '#options' => _notifications_content_type_options(),
          '#description' => t('Enable different subscription options for this content type.'),
          '#weight' => -10,
        );
        if (!variable_get('notifications_content_per_type', 0)) {
          $form['notifications']['notifications_content_type']['#disabled'] = TRUE;
          $form['notifications']['notifications_content_type']['#description'] .= ' <strong>' . t('To enable these options check the <a href="@notifications-settings">Notifications content settings</a>', array(
            '@notifications-settings' => url('admin/messaging/notifications/content'),
          )) . '</strong>';
        }
      }
      break;
    default:

      // Node form. Option to disable notifications
      if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
        $types = notifications_content_types(NULL);
        $node = $form['#node'];

        // Do not add if content type disabled, creating and create events disabled, updating and update events disabled
        if (notifications_content_type_enabled($node->type) && (empty($node->nid) && notifications_event_enabled('node', 'insert') || !empty($node->nid) && notifications_event_enabled('node', 'update'))) {
          _notifications_content_add_disable_field($form, !empty($node->notifications_content_disable));
        }
      }
  }
}