You are here

function simplenews_form_alter in Simplenews 6.2

Same name and namespace in other branches
  1. 5 simplenews.module \simplenews_form_alter()
  2. 6 simplenews.module \simplenews_form_alter()
  3. 7.2 simplenews.module \simplenews_form_alter()
  4. 7 simplenews.module \simplenews_form_alter()

Implementation of hook_form_alter().

File

./simplenews.module, line 816
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_form_alter(&$form, $form_state, $form_id) {
  $vid = variable_get('simplenews_vid', '');

  // Newsletter vocabulary form
  if ($form_id == 'taxonomy_form_vocabulary' && isset($form['vid']) && $form['vid']['#value'] == $vid) {

    // Hide critical options from newsletter vocabulary.
    $form['help_simplenews_vocab'] = array(
      '#value' => t('This is the designated simplenews vocabulary.'),
      '#weight' => -1,
    );

    // We display the current content type settings in a disabled form element
    // to the user. The real value passed in the form separately because
    // disabled elements do not get saved at submit.
    $form['content_types']['display_only'] = $form['content_types']['nodes'];
    $form['content_types']['display_only']['#disabled'] = TRUE;
    $form['content_types']['display_only']['#description'] = t('These content type(s) are used as newsletter. They can be set in !simplenews_settings.', array(
      '!simplenews_settings' => l('Simplenews settings', 'admin/settings/simplenews'),
    ));
    $form['content_types']['nodes'] = array(
      '#type' => 'value',
      '#value' => $form['content_types']['nodes']['#default_value'],
    );

    // Free tagging can not be allowed see: simplenews_validate_taxonomy().
    $form['settings']['tags'] = array(
      '#type' => 'value',
      '#value' => FALSE,
    );

    // Multiple select does not work with simplenews.
    $form['settings']['multiple'] = array(
      '#type' => 'value',
      '#value' => FALSE,
    );
    $form['settings']['required'] = array(
      '#type' => 'value',
      '#value' => TRUE,
    );
  }
  elseif (isset($form['type']) && isset($form['#node']) && strpos($form_id, '_node_form')) {
    if (in_array($form['type']['#value'], variable_get('simplenews_content_types', array(
      'simplenews',
    )))) {

      // Available variables are based on user_mail_tokens().
      // But uses only those which can be used with uid = 0 since simplenews also sends to anonymous users.
      if (isset($form['body_field'])) {
        $form['body_field']['body']['#description'] = t("This will be the body of your newsletter. See 'Replacement patterns' for available variables.)");
      }
      $form['simplenews_subscription']['subscription_mail']['token_help'] = array(
        '#title' => t('Replacement patterns'),
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#weight' => -20,
        '#description' => t('These tokens can be used in all text fields and will be replaced on-screen and in the email. Note that simplenews-receiver tokens are not suitable for on-screen use.'),
      );
      $form['simplenews_subscription']['subscription_mail']['token_help']['help'] = array(
        '#value' => theme('token_help', 'simplenews'),
      );
      $vocabulary = taxonomy_vocabulary_load(variable_get('simplenews_vid', ''));
      if (!empty($vocabulary) && !isset($vocabulary->nodes[$form['type']['#value']])) {
        drupal_set_message(t('Invalid vocabulary setting detected. Check and <strong>save</strong> the <a href="@settings">Simplenews general settings</a>.', array(
          '%name' => $vocabulary->name,
          '@settings' => url('admin/settings/simplenews'),
        )), 'error');
      }
    }
  }
}