You are here

function simplenews_form in Simplenews 5

Implementation of hook_form().

File

./simplenews.module, line 236

Code

function simplenews_form(&$node) {
  $type = node_get_types('type', $node);
  global $user;
  if ($type->has_title) {
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => check_plain($type->title_label),
      '#default_value' => $node->title,
      '#size' => 60,
      '#maxlength' => 128,
      '#required' => TRUE,
    );
  }
  if ($type->has_body) {
    $form['body_filter']['body'] = array(
      '#type' => 'textarea',
      '#title' => check_plain($type->body_label),
      '#default_value' => $node->body,
      '#rows' => 20,
      '#required' => $type->min_word_count > 0,
      '#description' => t('This will be the body of your newsletter. Available variables are:') . ' %site ' . t('(the name of your website),') . ' %uri ' . t('(a link to your homepage),') . ' %uri_brief ' . t('(homepage link without the http://),') . ' %mymail ' . t('(your e-mail address),') . ' %date ' . t('(today\'s date),') . ' %login_uri ' . t('(link to login page).'),
    );
    $form['body_filter']['format'] = filter_form($node->format);
  }
  if (!($sel1 = $node->s_format)) {
    $sel1 = variable_get('simplenews_format', 'plain');
  }
  if (!($sel2 = $node->priority)) {
    $sel2 = variable_get('simplenews_priority', 0);
  }
  if (!($sel3 = $node->receipt)) {
    $sel3 = variable_get('simplenews_receipt', 0);
  }
  $form['sending_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Newsletter sending options'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['sending_options']['s_format'] = array(
    '#type' => 'select',
    '#title' => t('Format'),
    '#default_value' => $sel1,
    '#options' => _simplenews_format_options(),
  );
  $form['sending_options']['priority'] = array(
    '#type' => 'select',
    '#title' => t('Priority'),
    '#default_value' => $sel2,
    '#options' => array(
      0 => t('none'),
      1 => t('highest'),
      2 => t('high'),
      3 => t('normal'),
      4 => t('low'),
      5 => t('lowest'),
    ),
  );
  $form['sending_options']['receipt'] = array(
    '#type' => 'checkbox',
    '#title' => t('Request receipt'),
    '#return_value' => 1,
    '#default_value' => $sel3,
  );
  if ($node->s_status == 0) {
    if (user_access('send newsletter')) {
      $options[0] = t("Don't send now");
      $options[2] = t('Send one test newsletter to the test address');
      $options[1] = t('Send newsletter');
      $form['sending_options']['send'] = array(
        '#type' => 'radios',
        '#title' => t('Sending'),
        '#default_value' => $node->send ? $node->send : variable_get('simplenews_send', 0),
        '#options' => $options,
      );
    }
    else {
      $options[0] = t("Don't send now");
      $options[2] = t('Send one test newsletter to the test address');
      $form['sending_options']['send'] = array(
        '#type' => 'radios',
        '#title' => t('Sending'),
        '#default_value' => $node->send ? $node->send : 0,
        '#options' => $options,
        '#description' => t('You have no privileges to send this newsletter'),
      );
    }
    if (variable_get('simplenews_test_address_override', 0)) {
      $form['sending_options']['test_address'] = array(
        '#type' => 'textfield',
        '#title' => t('Test e-mail addresses'),
        '#default_value' => $node->test_address ? $node->test_address : variable_get('simplenews_test_address', ''),
        '#size' => 60,
        '#maxlength' => 128,
        '#description' => t('Supply a comma-separated list of e-mail addresses to be used as test addresses.'),
      );
    }
  }
  else {
    $atts = array(
      'disabled' => 'disabled',
    );
    $form['sending_options']['none'] = array(
      '#type' => 'checkbox',
      '#title' => t('This newsletter has been sent'),
      '#return_value' => 0,
      '#attributes' => array(
        'checked' => 'checked',
        'disabled' => 'disabled',
      ),
    );
  }
  $form['s_status'] = array(
    '#type' => 'hidden',
    '#value' => $node->s_status ? $node->s_status : 0,
  );
  return $form;
}