diff --git a/src/Form/QuizResultEntityForm.php b/src/Form/QuizResultEntityForm.php index 4c82ef2cf..54badf857 100644 --- a/src/Form/QuizResultEntityForm.php +++ b/src/Form/QuizResultEntityForm.php @@ -95,10 +95,24 @@ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); } - public function validateForm(array &$form, FormStateInterface $form_state) { - parent::validateForm($form, $form_state); + /** + * {@inheritdoc} + * + * Start the quiz result if necessary. + */ + public function save(array $form, FormStateInterface $form_state) { + $new = $this->entity->isNew(); + // Save the quiz result. + parent::save($form, $form_state); + if ($new) { + // The user submitted a quiz result form to start a new attempt. Set the + // quiz result in the session. + /* @var $quiz_session \Drupal\quiz\Services\QuizSessionInterface */ + $quiz_session = \Drupal::service('quiz.session'); + $quiz_session->startQuiz($this->entity); + } } }