src/Controller/Front/Guest/RegistrationController.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Front\Guest;
  4. use App\Entity\UserGuest;
  5. use App\Form\FormFlow\GuestRegistrationFormFlow;
  6. use App\Service\Guest\RegistrationHandlerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class RegistrationController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/guest/registration", name="guest_registration")
  15.      */
  16.     public function index(Request $requestGuestRegistrationFormFlow $flowRegistrationHandlerInterface $handler): Response
  17.     {
  18.         $guest UserGuest::create();
  19.         $flow->bind($guest);
  20.         $form $flow->createForm();
  21.         if ($flow->isValid($form)) {
  22.             $flow->saveCurrentStepData($form);
  23.             if ($flow->nextStep()) {
  24.                 // form for the next step
  25.                 $form $flow->createForm();
  26.                 if ($flow->getCurrentStepLabel() === 'confirmation') {
  27.                     return $this->render('front/guest/registration/confirmation.html.twig', [
  28.                         'form' => $form->createView(),
  29.                         'guest' => $guest,
  30.                         'flow' => $flow,
  31.                     ]);
  32.                 }
  33.             } else {
  34.                 $handler->handle($guest);
  35.                 return $this->redirect($this->generateUrl('guest_registration_complete')); // redirect when done
  36.             }
  37.         }
  38.         return $this->render('front/guest/registration/index.html.twig', [
  39.             'form' => $form->createView(),
  40.             'flow' => $flow,
  41.         ]);
  42.     }
  43.     /**
  44.      * @Route("/guest/registration/complete", name="guest_registration_complete")
  45.      */
  46.     public function complete(): Response
  47.     {
  48.         return $this->render('front/guest/registration/complete.html.twig', []);
  49.     }
  50. }