src/Products/NotificationsBundle/Controller/Portal/OptInController.php line 63

Open in your IDE?
  1. <?php
  2. namespace Products\NotificationsBundle\Controller\Portal;
  3. use App\Component\ViewLayer\Views\DocHtmlView;
  4. use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaV3Type;
  5. use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueV3;
  6. use Products\NotificationsBundle\Controller\AbstractPortalController;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\Validator\Constraints\IsTrue;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. use Symfony\Component\Validator\Constraints\NotNull;
  15. /**
  16.  * @Route(
  17.  *     "/opt-in",
  18.  * )
  19.  */
  20. final class OptInController extends AbstractPortalController
  21. {
  22.     public const ROUTES__MAIN 'app.notifications.portal.opt_in.main';
  23.     public const ROUTES__NOTICE 'app.notifications.portal.opt_in.notice';
  24.     /**
  25.      * @param Request $request
  26.      * @return RedirectResponse|DocHtmlView
  27.      *
  28.      * @Route(
  29.      *     "",
  30.      *     name = self::ROUTES__MAIN,
  31.      * )
  32.      */
  33.     public function mainAction(Request $request): RedirectResponse|DocHtmlView
  34.     {
  35.         $form $this->createFormBuilder()
  36.             ->add('contact'TextType::class, [
  37.                 'required' => true,
  38.                 'attr' => [
  39.                     'autocomplete' => 'off',
  40.                     'inputmode' => 'email',
  41.                 ],
  42.                 'constraints' => [
  43.                     new NotNull(),
  44.                     new NotBlank(),
  45.                 ],
  46.             ])
  47.             ->add('terms'CheckboxType::class, [
  48.                 'required' => false,
  49.                 'constraints' => [
  50.                     new IsTrue(message'In order to proceed, you must agree to the Terms and Conditions and have reviewed the privacy policy.'),
  51.                 ],
  52.             ])
  53.             ->add('recaptcha'EWZRecaptchaV3Type::class, [
  54.                 'constraints' => [
  55.                     new IsTrueV3(),
  56.                 ],
  57.             ])
  58.             ->getForm();
  59.         if ($this->handleForm($form)) {
  60.             return $this->redirectToRoute(self::ROUTES__NOTICE);
  61.         }
  62.         return $this->html([
  63.             'form' => $form->createView(),
  64.         ]);
  65.     }
  66.     /**
  67.      * @return DocHtmlView
  68.      *
  69.      * @Route(
  70.      *     "/notice",
  71.      *     name = self::ROUTES__NOTICE,
  72.      * )
  73.      */
  74.     public function noticeAction(): DocHtmlView
  75.     {
  76.         return $this->html();
  77.     }
  78. }