You are here

public function LongAnswerQuestion::getAnsweringForm in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 question_types/quiz_long_answer/src/Plugin/quiz/QuizQuestion/LongAnswerQuestion.php \Drupal\quiz_long_answer\Plugin\quiz\QuizQuestion\LongAnswerQuestion::getAnsweringForm()
  2. 6.x question_types/quiz_long_answer/src/Plugin/quiz/QuizQuestion/LongAnswerQuestion.php \Drupal\quiz_long_answer\Plugin\quiz\QuizQuestion\LongAnswerQuestion::getAnsweringForm()

Get the form through which the user will answer the question.

Question types should populate the form with selected values from the current result if possible.

Parameters

FormStateInterface $form_state: Form state.

QuizResultAnswer $quizQuestionResultAnswer: The quiz result answer.

Return value

array Form array.

Overrides QuizQuestionEntityTrait::getAnsweringForm

File

question_types/quiz_long_answer/src/Plugin/quiz/QuizQuestion/LongAnswerQuestion.php, line 50

Class

LongAnswerQuestion
@QuizQuestion ( id = "long_answer", label = Plugin annotation @Translation("Long answer question"), handlers = { "response" = "\Drupal\quiz_long_answer\Plugin\quiz\QuizQuestion\LongAnswerResponse" } )

Namespace

Drupal\quiz_long_answer\Plugin\quiz\QuizQuestion

Code

public function getAnsweringForm(FormStateInterface $form_state, QuizResultAnswer $quizQuestionResultAnswer) {
  $element = parent::getAnsweringForm($form_state, $quizQuestionResultAnswer);
  $element += array(
    '#title' => t('Answer'),
    '#description' => t('Enter your answer here. If you need more space, click on the grey bar at the bottom of this area and drag it down.'),
    '#rows' => 15,
    '#cols' => 60,
  );
  if ($this
    ->get('answer_text_processing')
    ->getString()) {
    $element['#type'] = 'text_format';
  }
  else {
    $element['#type'] = 'textarea';
  }
  if ($quizQuestionResultAnswer
    ->isAnswered()) {
    $element['#default_value'] = $quizQuestionResultAnswer
      ->getResponse();
  }
  return $element;
}