You are here

public static function MatchingQuestion::getAnsweringFormValidate in Quiz 8.6

Same name and namespace in other branches
  1. 8.5 question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingQuestion.php \Drupal\quiz_matching\Plugin\quiz\QuizQuestion\MatchingQuestion::getAnsweringFormValidate()
  2. 6.x question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingQuestion.php \Drupal\quiz_matching\Plugin\quiz\QuizQuestion\MatchingQuestion::getAnsweringFormValidate()

Question response validator.

Overrides QuizQuestionEntityTrait::getAnsweringFormValidate

File

question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingQuestion.php, line 82
Matching classes.

Class

MatchingQuestion
@QuizQuestion ( id = "matching", label = Plugin annotation @Translation("Matching question"), handlers = { "response" = "\Drupal\quiz_matching\Plugin\quiz\QuizQuestion\MatchingResponse" } )

Namespace

Drupal\quiz_matching\Plugin\quiz\QuizQuestion

Code

public static function getAnsweringFormValidate(array &$element, Drupal\Core\Form\FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $id = $element['#quiz_result_answer']
    ->getQuizQuestion()
    ->id();
  if (!array_filter($values['question'][$id]['answer']['user_answer'])) {
    $form_state
      ->setError($element, t('You need to match at least one of the items.'));
  }
}