public function QuizQuestionEntityForm::save in Quiz 6.x
Redirect to questions form after quiz creation.
Overrides EntityForm::save
File
- src/
Form/ QuizQuestionEntityForm.php, line 76
Class
- QuizQuestionEntityForm
- Quiz question authoring form.
Namespace
Drupal\quiz\FormCode
public function save(array $form, FormStateInterface $form_state) {
$quiz_question = $this->entity;
$insert = $quiz_question
->isNew();
parent::save($form, $form_state);
if ($qid = $form_state
->getValue('quiz_id')) {
// Add to quiz if coming from the questions form.
$vid = $form_state
->getValue('quiz_vid');
/* @var $quiz Quiz */
$quiz = Drupal::entityTypeManager()
->getStorage('quiz')
->loadRevision($vid);
$quiz
->addQuestion($this->entity);
}
$type = QuizQuestionType::load($quiz_question
->bundle());
$t_args = [
'@type' => $type
->label(),
'%title' => $quiz_question
->toLink()
->toString(),
];
if ($insert) {
$this
->messenger()
->addStatus($this
->t('@type %title has been created.', $t_args));
}
else {
$this
->messenger()
->addStatus($this
->t('@type %title has been updated.', $t_args));
}
if ($qid = $form_state
->getValue('quiz_id')) {
$form_state
->setRedirect('quiz.questions', [
'quiz' => $qid,
]);
}
}