You are here

public function QuizQuestionAnsweringForm::validateForm in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 src/Form/QuizQuestionAnsweringForm.php \Drupal\quiz\Form\QuizQuestionAnsweringForm::validateForm()
  2. 6.x src/Form/QuizQuestionAnsweringForm.php \Drupal\quiz\Form\QuizQuestionAnsweringForm::validateForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/QuizQuestionAnsweringForm.php, line 346

Class

QuizQuestionAnsweringForm

Namespace

Drupal\quiz\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('quiz.settings');
  $quiz_result = QuizResult::load($form_state
    ->getBuildInfo()['args'][1]);

  /* @var $quiz Drupal\quiz\Entity\Quiz */
  $quiz = \Drupal::entityTypeManager()
    ->getStorage('quiz')
    ->loadRevision($quiz_result
    ->get('vid')
    ->getString());
  $questions = $quiz_result
    ->getLayout();
  $time_reached = !$quiz
    ->get('time_limit')
    ->isEmpty() && \Drupal::time()
    ->getRequestTime() > $quiz_result
    ->get('time_start')
    ->getString() + $quiz
    ->get('time_limit')
    ->getString() + $config
    ->get('quiz_time_limit_buffer', 5);
  if ($time_reached) {

    // Let's not validate anything, because the input won't get saved in submit
    // either.
    return;
  }
}