feat: add bank question via modal + dirty modal guard

- Add question in question bank now opens a modal instead of navigating
  to a full-page form, consistent with the edit modal pattern
- Modal closes are blocked by static backdrop once the user has made any
  change (input, checkbox, drag-reorder, sort, randomize, remove answer)
- Dirty state resets when the modal is fully hidden
This commit is contained in:
2026-07-06 22:32:44 +02:00
parent 394b8c7d33
commit 4a87ac574d
4 changed files with 52 additions and 2 deletions
@@ -88,6 +88,8 @@ class QuestionBankController extends AbstractController
{
$bankQuestion = new BankQuestion();
$isModalRequest = $request->headers->has('X-Modal-Request');
$form = $this->createForm(BankQuestionFormType::class, $bankQuestion, ['season' => $season]);
$form->handleRequest($request);
@@ -99,14 +101,29 @@ class QuestionBankController extends AbstractController
$this->addFlash(FlashType::Success, $this->translator->trans('Question added to the question bank'));
if ($isModalRequest) {
return new Response('', Response::HTTP_NO_CONTENT);
}
return $this->redirectToRoute('tvdt_backoffice_question_bank', ['seasonCode' => $season->seasonCode]);
}
return $this->render('backoffice/question_bank/form.html.twig', [
$template = $isModalRequest
? 'backoffice/question_bank/_form_body.html.twig'
: 'backoffice/question_bank/form.html.twig';
$response = $this->render($template, [
'season' => $season,
'form' => $form,
'bankQuestion' => null,
'isModal' => $isModalRequest,
]);
if ($form->isSubmitted()) {
$response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY);
}
return $response;
}
#[IsGranted(SeasonVoter::EDIT, subject: 'season')]