You are here

function notifications_add_subscription_form in Notifications 6.3

Same name and namespace in other branches
  1. 6 notifications.pages.inc \notifications_add_subscription_form()
  2. 6.2 notifications.pages.inc \notifications_add_subscription_form()

Form for creating new subscriptions

1 string reference to 'notifications_add_subscription_form'
notifications_ui_page_user_add in notifications_ui/notifications_ui.pages.inc
User add subscription

File

./notifications.pages.inc, line 67
User pages for Notifications

Code

function notifications_add_subscription_form($form_state, $account, $type, $destination = NULL) {
  $destination = $destination ? $destination : 'user/' . $account->uid . '/notifications';
  $info = notifications_subscription_types($type);
  $form['account'] = array(
    '#type' => 'value',
    '#value' => $account,
  );
  $form['type'] = array(
    '#type' => 'value',
    '#value' => $type,
  );

  // Display general information
  $form['info'] = array(
    '#type' => 'fieldset',
    '#title' => t('Create @type subscription', array(
      '@type' => $info['title'],
    )),
    '#description' => !empty($info['description']) ? $info['description'] : '',
  );

  // Build subscription fields
  $form['info']['fields']['#tree'] = TRUE;
  foreach ($info['fields'] as $fid => $field_type) {
    $field = notifications_subscription_fields($field_type);
    $form['info']['fields'][$fid]['type'] = array(
      '#type' => 'value',
      '#value' => $field_type,
    );
    $form['info']['fields'][$fid]['value'] = notifications_subscription_form_field($field_type, NULL, $type);
    $form['info']['fields'][$fid]['value'] += array(
      '#title' => $field['name'],
      '#required' => TRUE,
    );
  }

  // Add generic subscription information for notifications
  $form['notifications'] = array(
    '#type' => 'fieldset',
    '#title' => t('Notifications'),
    '#description' => t('How often and by which channel do you want to get notifications for this subscription.'),
  );
  $form['notifications']['send_interval'] = array(
    '#type' => 'select',
    '#title' => t('Send interval'),
    '#options' => _notifications_send_intervals(),
    '#default_value' => notifications_user_setting('send_interval', $account),
  );
  $send_methods = _notifications_send_methods($account);
  $form['notifications']['send_method'] = array(
    '#type' => 'select',
    '#title' => t('Send method'),
    '#options' => $send_methods,
    '#default_value' => notifications_user_setting('send_method', $account),
  );

  // Other form parameters and buttons
  $form['#redirect'] = $destination;
  $form['buttons']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Create subscription'),
  );
  $form['buttons']['cancel'] = array(
    '#value' => l(t('Cancel'), $destination),
  );
  return $form;
}