You are here

function _simplenews_subscription_manager_form in Simplenews 5

Same name and namespace in other branches
  1. 6 simplenews.module \_simplenews_subscription_manager_form()

Helper function to build subscription manager form, also used in user edit.

2 calls to _simplenews_subscription_manager_form()
simplenews_subscription_manager_form in ./simplenews.module
Generates the subscription form for users.
simplenews_user in ./simplenews.module
Implementation of hook_user().

File

./simplenews.module, line 967

Code

function _simplenews_subscription_manager_form($subscription) {
  global $user;
  $form = array();
  $form['#base'] = 'simplenews_subscription_manager_form';
  $options = array();
  foreach (taxonomy_get_tree(variable_get('simplenews_vid', '')) as $newsletter) {
    $options[$newsletter->tid] = check_plain($newsletter->name);
  }
  $form['subscriptions'] = array(
    '#type' => 'fieldset',
    '#description' => t('Select the newsletter(s) to which you want to subscribe or unsubscribe.'),
  );
  $form['subscriptions']['newsletters'] = array(
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => $subscription->tids,
  );

  // If current user is an authenticated, just display e-mail. Anonymous users
  // see an e-mail box and will receive confirmations
  if ($user->uid) {
    $form['subscriptions']['#title'] = t('Subscriptions for %mail', array(
      '%mail' => $subscription->mail,
    ));
    $form['subscriptions']['mail'] = array(
      '#type' => 'value',
      '#value' => $subscription->mail,
    );
    $form['update'] = array(
      '#type' => 'submit',
      '#value' => t('Update'),
      '#weight' => 20,
    );
  }
  else {
    $form['subscriptions']['#title'] = t('Manage your newsletter subscriptions');
    $form['subscriptions']['mail'] = array(
      '#type' => 'textfield',
      '#title' => t('E-mail'),
      '#size' => 20,
      '#maxlength' => 128,
      '#weight' => 10,
      '#required' => TRUE,
    );
    $form['subscribe'] = array(
      '#type' => 'submit',
      '#value' => t('Subscribe'),
      '#weight' => 20,
    );
    $form['unsubscribe'] = array(
      '#type' => 'submit',
      '#value' => t('Unsubscribe'),
      '#weight' => 30,
    );
  }
  return $form;
}