public function QuizQuestionAnsweringForm::submitBlank in Quiz 8.5
Same name and namespace in other branches
- 8.6 src/Form/QuizQuestionAnsweringForm.php \Drupal\quiz\Form\QuizQuestionAnsweringForm::submitBlank()
- 6.x src/Form/QuizQuestionAnsweringForm.php \Drupal\quiz\Form\QuizQuestionAnsweringForm::submitBlank()
Submit action for "leave blank".
File
- src/
Form/ QuizQuestionAnsweringForm.php, line 255
Class
Namespace
Drupal\quiz\FormCode
public function submitBlank(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());
$questions = $quiz_result
->getLayout();
if (!empty($form_state
->getUserInput()['question'])) {
// Loop over all question inputs provided, and record them as skipped.
foreach (array_keys($form_state
->getUserInput()['question']) as $qqid) {
foreach ($quiz_result
->getLayout() as $idx => $qra) {
// Find the blank submitted question in the current layout.
if ($qra
->get('question_id')
->getString() == $qqid) {
// Reset the question and mark it as taken, so restrictions like
// backwards navigation function correctly.
$qra
->set('is_skipped', TRUE);
$qra
->set('is_correct', FALSE);
$qra
->set('points_awarded', FALSE);
$qra
->set('answer_timestamp', \Drupal::time()
->getRequestTime());
$qra
->save();
}
}
$quiz_result
->setQuestion($_SESSION['quiz'][$quiz
->id()]['current'] + 1);
}
}
else {
// Advance to next question, no input here.
$quiz_result
->setQuestion($quiz, $_SESSION['quiz'][$quiz
->id()]['current'] + 1);
}
// Advance to next question.
$form_state
->setRedirect('quiz.question.take', [
'quiz' => $quiz
->id(),
'question_number' => $_SESSION['quiz'][$quiz
->id()]['current'],
]);
$layout = $quiz_result
->getLayout();
if (!isset($layout[$_SESSION['quiz'][$quiz
->id()]['current']])) {
// If this is the last question, finalize the quiz.
$this
->submitFinalize($form, $form_state);
}
}