You are here

function answers_best_answer_form_alter in Answers 7.4

Implements hook_form_alter().

File

answers_best_answer/answers_best_answer.module, line 29
Support selection of 'Best Answers' for the 'Answers' module.

Code

function answers_best_answer_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {

    // Add settings for answers_best_answer to the answers settings form.
    case 'answers_settings':
      $form['additional_settings']['#attached']['js'][] = drupal_get_path('module', 'answers_best_answer') . '/js/answers_best_answer_admin.js';
      $old = variable_get('answers_best_answer_lock_questions_p', 0);
      $form['answers_question_lock_settings']['answers_best_answer_lock_questions_p'] = array(
        '#type' => 'checkbox',
        '#title' => t('Lock !questions after a "Best !Answer" has been selected', answers_translation()),
        '#description' => t('After a !question author selects a "Best !Answer", should users be blocked from adding new !answers?', answers_translation()),
        '#default_value' => $old,
      );

      // Store the old value.
      $form['answers_question_lock_settings']['answers_best_answer_old_lock_questions_p'] = array(
        '#type' => 'value',
        '#value' => $old,
      );
      $old = variable_get('answers_best_answer_lock_choice_p', 0);
      $form['answers_question_lock_settings']['answers_best_answer_lock_choice_p'] = array(
        '#type' => 'checkbox',
        '#title' => t('Lock best !answers', answers_translation()),
        '#description' => t('When a !question is locked, should the choice of best !answer also be locked?', answers_translation()),
        '#default_value' => $old,
      );

      // Store the old value.
      $form['answers_question_lock_settings']['answers_best_answer_old_lock_choice_p'] = array(
        '#type' => 'value',
        '#value' => $old,
      );

      // Add in a submit handler *before* the standard handler.
      $form['#submit'][] = 'answers_best_answer_settings_form_submit';
      $form['renaming']['answer'][ANSWERS_BEST_ANSWER_TRANS_UCUNANSWERED] = array(
        '#type' => 'textfield',
        '#title' => t('Unanswered'),
        '#description' => t('Word to use in the interface for the upper case word !Unanswered', answers_translation()),
        '#default_value' => variable_get(ANSWERS_BEST_ANSWER_TRANS_UCUNANSWERED, 'Unanswered'),
        '#size' => 20,
        '#maxlength' => 20,
      );
      $form['renaming']['answer'][ANSWERS_BEST_ANSWER_TRANS_LCUNANSWERED] = array(
        '#type' => 'textfield',
        '#title' => t('unanswered'),
        '#description' => t('Word to use in the interface for the lower case  word !unanswered', answers_translation()),
        '#default_value' => variable_get(ANSWERS_BEST_ANSWER_TRANS_LCUNANSWERED, 'unanswered'),
        '#size' => 20,
        '#maxlength' => 20,
      );
      break;
  }
}