You are here

public static function LongAnswerQuestion::getAnsweringFormValidate 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::getAnsweringFormValidate()
  2. 6.x question_types/quiz_long_answer/src/Plugin/quiz/QuizQuestion/LongAnswerQuestion.php \Drupal\quiz_long_answer\Plugin\quiz\QuizQuestion\LongAnswerQuestion::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_long_answer/src/Plugin/quiz/QuizQuestion/LongAnswerQuestion.php, line 77

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 static function getAnsweringFormValidate(array &$element, FormStateInterface $form_state) {
  parent::getAnsweringFormValidate($element, $form_state);
  if (isset($element['value'])) {
    $check =& $element['value'];
  }
  else {
    $check =& $element;
  }
  if (empty($check['#value'])) {
    $form_state
      ->setError($check, t('You must provide an answer.'));
  }
}