You are here

function _simplenews_subscription_manager_form in Simplenews 6

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

Build subscription manager form.

Parameters

object $subscription subscription object:

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

File

./simplenews.module, line 1201
Simplnews node handling, sent email, newsletter block and general hooks

Code

function _simplenews_subscription_manager_form($subscription) {
  $form = array();
  $options = array();
  $default_value = array();
  global $language;

  // Get taxonomy terms for subscription form checkboxes.
  // With taxonomy translation and 'Per language terms' only the terms of the
  // current language are listed. With taxonomy translation and 'Localize terms'
  // all taxonomy terms are listed and translated.
  if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_TRANSLATE) {

    // Per language terms.
    $tterms = i18ntaxonomy_vocabulary_get_terms(variable_get('simplenews_vid', ''), $language->language);
    foreach ($tterms as $tid => $name) {
      $options[$tid] = check_plain($name);
      $default_value[$tid] = FALSE;
    }
  }
  else {
    foreach (taxonomy_get_tree(variable_get('simplenews_vid', '')) as $newsletter) {
      if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_LOCALIZE) {

        // Localize terms.
        $options[$newsletter->tid] = check_plain(tt('taxonomy:term:' . $newsletter->tid . ':name', $newsletter->name, $language->language));
      }
      else {

        // Untranslated.
        $options[$newsletter->tid] = check_plain($newsletter->name);
      }
      $default_value[$newsletter->tid] = FALSE;
    }
  }
  $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' => array_merge($default_value, (array) $subscription->tids),
  );

  // If current user is logged in, just display email.
  // Anonymous users see an email box and will receive confirmations
  if ($subscription->mail) {
    $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('email'),
      '#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;
}