function QuizQuestionAnsweringForm::submitFinalize in Quiz 8.5
Same name and namespace in other branches
- 8.6 src/Form/QuizQuestionAnsweringForm.php \Drupal\quiz\Form\QuizQuestionAnsweringForm::submitFinalize()
- 6.x src/Form/QuizQuestionAnsweringForm.php \Drupal\quiz\Form\QuizQuestionAnsweringForm::submitFinalize()
Helper function to finalize a quiz attempt.
See also
quiz_question_answering_form_submit()
quiz_question_answering_form_submit_blank()
2 calls to QuizQuestionAnsweringForm::submitFinalize()
- QuizQuestionAnsweringForm::submitBlank in src/
Form/ QuizQuestionAnsweringForm.php - Submit action for "leave blank".
- QuizQuestionAnsweringForm::submitForm in src/
Form/ QuizQuestionAnsweringForm.php - Submit handler for the question answering form.
File
- src/
Form/ QuizQuestionAnsweringForm.php, line 300
Class
Namespace
Drupal\quiz\FormCode
function submitFinalize(array $form, FormStateInterface $form_state) {
$quiz_result = QuizResult::load($form_state
->getBuildInfo()['args'][1]);
$quiz = \Drupal::entityTypeManager()
->getStorage('quiz')
->loadRevision($quiz_result
->get('vid')
->getString());
// No more questions. Score quiz and finalize result.
$quiz_result
->finalize();
if (empty($quiz->review_options['question']) || !array_filter($quiz->review_options['question']) || empty($form_state['feedback'])) {
// Only redirect to question results if there is not question feedback.
// /** @todo D8*/
$form_state
->setRedirect('entity.quiz_result.canonical', [
'quiz' => $quiz
->id(),
'quiz_result' => $quiz_result
->id(),
]);
}
// Remove all information about this quiz from the session.
// @todo but for anon, we might have to keep some so they could access
// results
// When quiz is completed we need to make sure that even though the quiz has
// been removed from the session, that the user can still access the
// feedback for the last question, THEN go to the results page.
$_SESSION['quiz']['temp']['result_id'] = $quiz_result
->id();
unset($_SESSION['quiz'][$quiz
->id()]);
}