You are here

public static function ShortAnswerQuestion::getAnsweringFormValidate in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 question_types/quiz_short_answer/src/Plugin/quiz/QuizQuestion/ShortAnswerQuestion.php \Drupal\quiz_short_answer\Plugin\quiz\QuizQuestion\ShortAnswerQuestion::getAnsweringFormValidate()
  2. 8.5 question_types/quiz_short_answer/src/Plugin/quiz/QuizQuestion/ShortAnswerQuestion.php \Drupal\quiz_short_answer\Plugin\quiz\QuizQuestion\ShortAnswerQuestion::getAnsweringFormValidate()

Validate a user's answer.

Parameters

array $element: The form element of this question.

mixed $form_state: Form state.

Overrides QuizQuestionEntityTrait::getAnsweringFormValidate

File

question_types/quiz_short_answer/src/Plugin/quiz/QuizQuestion/ShortAnswerQuestion.php, line 90

Class

ShortAnswerQuestion
@QuizQuestion ( id = "short_answer", label = Plugin annotation @Translation("Short answer question"), handlers = { "response" = "\Drupal\quiz_short_answer\Plugin\quiz\QuizQuestion\ShortAnswerResponse" } )

Namespace

Drupal\quiz_short_answer\Plugin\quiz\QuizQuestion

Code

public static function getAnsweringFormValidate(array &$element, FormStateInterface $form_state) {
  if ($element['#value'] == '') {
    $form_state
      ->setError($element, t('You must provide an answer.'));
  }
}