You are here

function oa_notifications_form_fields in Open Atrium Notifications 7.2

Define the fields that are used for configuring notifications.

2 calls to oa_notifications_form_fields()
oa_notifications_edit_form in plugins/content_types/oa_notifications_pane.inc
Render the edit form for Notifications
oa_notifications_form_node_form_alter in ./oa_notifications.module
Implements hook_form_node_form_alter().

File

./oa_notifications.module, line 544

Code

function oa_notifications_form_fields(&$form, &$form_state, $node) {
  $nid = isset($node->nid) ? $node->nid : 0;
  $form['#node'] = $node;
  $form['source_type'] = array(
    '#type' => 'value',
    '#value' => 'node',
  );
  $form['source_id'] = array(
    '#type' => 'value',
    '#value' => $nid,
  );
  $default = array(
    'group' => array(),
    'team' => array(),
    'user' => array(),
  );
  $triggering = isset($form_state['triggering_element']) ? $form_state['triggering_element']['#name'] : '';

  // Get from form state, if available, for AJAX.
  if ($triggering == 'oa_notifications[override]') {
    $override = !empty($form_state['input'][OA_NOTIFY_FORM]['override']);
    if (!empty($node->nid)) {
      oa_notifications_save_override('node', $node->nid, $override);
    }
  }
  else {
    $override = isset($form_state['input'][OA_NOTIFY_FORM]['override']) ? $form_state['input'][OA_NOTIFY_FORM]['override'] : ($node->type == 'oa_section' ? oa_notifications_is_overriding('node', $nid) : TRUE);
  }
  if ($node->type == 'oa_section') {

    // Sections are handled differently due to space inheritance and overriding.
    $form['override'] = array(
      '#type' => 'checkbox',
      '#title' => t('Override default space notifications'),
      '#default_value' => $override,
      '#ajax' => array(
        'wrapper' => 'notify-list',
        'callback' => 'oa_notifications_form_fields_override_ajax',
      ),
    );
    $notifications = $override ? oa_notifications_load_multiple($node) : oa_notifications_get_default_notifications(0, 0, FALSE);
  }
  elseif (!empty($triggering)) {

    // Load current notifications if we are in an ajax rebuild.
    $notifications = $form_state['storage']['notification_data'];
  }
  else {

    // content node or Space node, check for parent space in URL for defaults.
    $parent = 0;
    $section = 0;
    if (!empty($_GET[OA_PARENT_SPACE]) && is_numeric($_GET[OA_PARENT_SPACE])) {
      $parent = $_GET[OA_PARENT_SPACE];
      $section = FALSE;
    }
    if (!empty($_GET[OA_SECTION_FIELD]) && is_numeric($_GET[OA_SECTION_FIELD])) {
      $section = $_GET[OA_SECTION_FIELD];
    }
    $notifications = $nid ? oa_notifications_load_multiple($node) : oa_notifications_get_default_notifications($section, $parent, $node->type != OA_SPACE_TYPE);
  }
  if ($triggering == OA_NOTIFY_FORM . '[notify_list][combined]') {
    oa_notifications_process_remove($notifications, $form_state);
    if (isset($form_state['input'][OA_NOTIFY_FORM]['notify_list']['combined'])) {
      oa_notification_parse($form_state['input'][OA_NOTIFY_FORM]['notify_list']['combined'], 'node', $nid, $notifications);
    }
  }
  else {
    $notifications = array_merge($default, $notifications);
  }
  $form['subscribe'] = isset($form_state['want form']) ? array() : oa_notifications_subscribe_button($node);
  $form['notify_list'] = oa_notifications_build_list_form($node, $override, !empty($form_state['want form']), $notifications);
  $form_state['storage']['notification_data'] = $notifications;
  oa_notifications_reset();
  $using_defaults = !empty($form_state['want form']) && in_array($node->type, array(
    OA_SPACE_TYPE,
    OA_GROUP_TYPE,
    OA_SECTION_TYPE,
  ));
  $form['skip_notify'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not send notifications for this update.'),
    '#ajax' => array(
      'callback' => 'oa_notifications_skip_ajax_callback',
      'wrapper' => 'skip-notify-div',
      'method' => 'replace',
    ),
    '#prefix' => '<div id="skip-notify-div">',
    '#suffix' => '</div>',
    '#access' => !empty($form_state['want form']) || _oa_notification_show_skip($node),
    '#default_value' => $using_defaults,
  );
}