You are here

function og_notifications_add_form in Organic groups 6.2

Same name and namespace in other branches
  1. 5.3 og_notifications/og_notifications.module \og_notifications_add_form()

Grouptype subscription creation form.

Parameters

Object $account: User object of the user whose page is to be displayed.

Return value

Array $form Form array.

1 string reference to 'og_notifications_add_form'
og_notifications_user_page in modules/og_notifications/og_notifications.pages.inc
Menu callback: Display the user subscription management forms.

File

modules/og_notifications/og_notifications.pages.inc, line 47
Group subscriptions management methods.

Code

function og_notifications_add_form($form_state, $account, $groups) {
  $content_types = array_filter(variable_get('og_notifications_content_types', array()));
  $content_names = node_get_types('names');
  foreach ($content_types as $type) {
    $content_types[$type] = $content_names[$type];
  }
  $defaults = _notifications_subscription_defaults($account);
  $send_methods = _notifications_send_methods();
  $send_intervals = _notifications_send_intervals();
  $header = array(
    t('Group'),
    t('Type'),
    t('Send method'),
    t('Send Interval'),
  );

  // Reuse notifications theme function for the embedded table. This also
  // necessitates the use of a keyed array.
  $form['subscription'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add subscription'),
    '#tree' => TRUE,
    '#header' => &$header,
  );
  $form['subscription']['group'][0] = array(
    '#type' => 'select',
    '#options' => $groups,
    '#title' => t('Group'),
  );
  $form['subscription']['node_type'][0] = array(
    '#type' => 'select',
    '#options' => array(
      'all' => t('All content types'),
    ) + $content_types,
    '#title' => t('Notify me of new content of these types'),
  );

  // Hide send methods if only one available.
  if (count($send_methods) > 1) {
    $form['subscription']['send_method'][0] = array(
      '#type' => 'select',
      '#options' => $send_methods,
      '#default_value' => $defaults['send_method'],
      '#title' => t('Send method'),
    );
  }
  else {

    // Unset send method column if only one is available.
    unset($header[2]);

    // Pass default outside the subscriptions fieldset to avoid theming issues.
    $form['send_method'] = array(
      '#type' => 'value',
      '#value' => $defaults['send_method'],
    );
  }
  $form['subscription']['send_interval'][0] = array(
    '#type' => 'select',
    '#options' => $send_intervals,
    '#default_value' => $defaults['send_interval'],
    '#title' => t('Send interval'),
  );
  $form['subscription']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add'),
  );
  $form['account'] = array(
    '#type' => 'value',
    '#value' => $account,
  );
  return $form;
}