You are here

public function ShortAnswerQuestion::getCreationForm in Quiz 8.4

Implementation of getCreationForm

Overrides QuizQuestion::getCreationForm

See also

QuizQuestion#getCreationForm($form_state)

File

question_types/short_answer/lib/Drupal/short_answer/ShortAnswerQuestion.php, line 169
The main classes for the short answer question type.

Class

ShortAnswerQuestion
Extension of QuizQuestion.

Namespace

Drupal\short_answer

Code

public function getCreationForm(array &$form_state = NULL) {
  $form['answer'] = array(
    '#type' => 'fieldset',
    '#title' => t('Answer'),
    '#description' => t('Provide the answer and the method by which the answer will be evaluated.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#weight' => -4,
  );
  $options = array(
    self::ANSWER_MATCH => t('Automatic and case sensitive'),
    self::ANSWER_INSENSITIVE_MATCH => t('Automatic. Not case sensitive'),
  );
  $access_regex = user_access('use regex for short answer');
  if ($access_regex) {
    $options[self::ANSWER_REGEX] = t('Match against a regular expression (answer must match the supplied regular expression)');
  }
  $options[self::ANSWER_MANUAL] = t('Manual');
  $form['answer']['correct_answer_evaluation'] = array(
    '#type' => 'radios',
    '#title' => t('Pick an evaluation method'),
    '#description' => t('Choose how the answer shall be evaluated.'),
    '#options' => $options,
    '#default_value' => isset($this->node->correct_answer_evaluation) ? $this->node->correct_answer_evaluation : self::ANSWER_MATCH,
    '#required' => FALSE,
  );
  if ($access_regex) {
    $form['answer']['regex_box'] = array(
      '#type' => 'fieldset',
      '#title' => t('About regular expressions'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['answer']['regex_box']['regex_help'] = array(
      '#markup' => '<p>' . t('Regular expressions are an advanced syntax for pattern matching. They allow you to create a concise set of rules that must be met before a value can be considered a match.') . '</p><p>' . t('For more on regular expression syntax, visit !url.', array(
        '!url' => l('the PHP regular expressions documentation', 'http://www.php.net/manual/en/book.pcre.php'),
      )) . '</p>',
    );
  }
  $form['answer']['correct_answer'] = array(
    '#type' => 'textfield',
    '#title' => t('Correct answer'),
    '#description' => t('Specify the answer. If this question is manually scored, no answer needs to be supplied.'),
    '#default_value' => isset($this->node->correct_answer) ? $this->node->correct_answer : '',
    '#size' => 60,
    '#maxlength' => 256,
    '#required' => FALSE,
  );
  return $form;
}