You are here

function notifications_content_form in Notifications 6.2

Same name and namespace in other branches
  1. 5 notifications_content/notifications_content.module \notifications_content_form()
  2. 6 notifications_content/notifications_content.pages.inc \notifications_content_form()
  3. 6.3 notifications_content/notifications_content.pages.inc \notifications_content_form()

Generic subscriptions content form

File

notifications_content/notifications_content.pages.inc, line 156
Subscriptions to content events

Code

function notifications_content_form($account, $subscriptions, $list, $field, $field_title, $defaults = array()) {

  // Complete defaults
  $defaults += array(
    'sid' => 0,
    'send_interval' => notifications_user_setting('send_interval', $account),
    'send_method' => notifications_user_setting('send_method', $account),
    'event_type' => 'node',
  );
  $form['defaults'] = array(
    '#type' => 'value',
    '#value' => $defaults,
  );
  $form['account'] = array(
    '#type' => 'value',
    '#value' => $account,
  );
  $form['current'] = array(
    '#type' => 'value',
    '#value' => $subscriptions,
  );
  $form['subscription_fields'] = array(
    '#type' => 'value',
    '#value' => array(),
  );
  $form['subscriptions'] = array(
    '#tree' => TRUE,
    '#theme' => 'notifications_form_table',
    '#header' => array(
      '',
      $field_title,
      t('Send interval'),
      t('Send method'),
    ),
  );
  foreach ($list as $key => $title) {
    $rowdefaults = isset($subscriptions[$key]) ? (array) $subscriptions[$key] : $defaults;
    $rowdefaults += $rowdefaults;
    $form['subscriptions']['checkbox'][$key] = array(
      '#type' => 'checkbox',
      '#default_value' => $rowdefaults['sid'],
    );
    $form['subscriptions']['title'][$key] = array(
      '#value' => $title,
    );
    $form['subscriptions']['send_interval'][$key] = array(
      '#type' => 'select',
      '#options' => notifications_send_intervals(),
      '#default_value' => $rowdefaults['send_interval'],
    );
    $form['subscriptions']['send_method'][$key] = array(
      '#type' => 'select',
      '#options' => _notifications_send_methods(),
      '#default_value' => $rowdefaults['send_method'],
    );

    // Pass on the fields for processing
    $form['subscription_fields']['#value'][$key] = array(
      $field => $key,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}