You are here

function og_notifications_add_form in Organic groups 5.3

Same name and namespace in other branches
  1. 6.2 modules/og_notifications/og_notifications.pages.inc \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 og_notifications/og_notifications.module
Menu callback: Display the user subscription management forms.

File

og_notifications/og_notifications.module, line 425
Provide notifications and messaging support for organic groups.

Code

function og_notifications_add_form($account) {
  $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();
  foreach ($account->og_groups as $gid => $group) {
    $account->og_groups[$gid] = $group['title'];
  }
  $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,
    '#collapsible' => TRUE,
    '#theme' => 'notifications_form_table',
    '#header' => &$header,
  );
  $form['subscription']['group'][0] = array(
    '#type' => 'select',
    '#options' => $account->og_groups,
  );
  $form['subscription']['node_type'][0] = array(
    '#type' => 'select',
    '#options' => array(
      'all' => t('All content types'),
    ) + $content_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'],
    );
  }
  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'],
  );
  $form['subscription']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add'),
  );
  $form['account'] = array(
    '#type' => 'value',
    '#value' => $account,
  );
  return $form;
}