<?php
declare(strict_types=1);
namespace App\Controller\Front\Guest;
use App\Entity\UserGuest;
use App\Form\FormFlow\GuestRegistrationFormFlow;
use App\Service\Guest\RegistrationHandlerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class RegistrationController extends AbstractController
{
/**
* @Route("/guest/registration", name="guest_registration")
*/
public function index(Request $request, GuestRegistrationFormFlow $flow, RegistrationHandlerInterface $handler): Response
{
$guest = UserGuest::create();
$flow->bind($guest);
$form = $flow->createForm();
if ($flow->isValid($form)) {
$flow->saveCurrentStepData($form);
if ($flow->nextStep()) {
// form for the next step
$form = $flow->createForm();
if ($flow->getCurrentStepLabel() === 'confirmation') {
return $this->render('front/guest/registration/confirmation.html.twig', [
'form' => $form->createView(),
'guest' => $guest,
'flow' => $flow,
]);
}
} else {
$handler->handle($guest);
return $this->redirect($this->generateUrl('guest_registration_complete')); // redirect when done
}
}
return $this->render('front/guest/registration/index.html.twig', [
'form' => $form->createView(),
'flow' => $flow,
]);
}
/**
* @Route("/guest/registration/complete", name="guest_registration_complete")
*/
public function complete(): Response
{
return $this->render('front/guest/registration/complete.html.twig', []);
}
}