<?php
namespace Products\NotificationsBundle\Controller\Portal;
use App\Component\ViewLayer\Views\DocHtmlView;
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaV3Type;
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueV3;
use Products\NotificationsBundle\Controller\AbstractPortalController;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
/**
* @Route(
* "/opt-in",
* )
*/
final class OptInController extends AbstractPortalController
{
public const ROUTES__MAIN = 'app.notifications.portal.opt_in.main';
public const ROUTES__NOTICE = 'app.notifications.portal.opt_in.notice';
/**
* @param Request $request
* @return RedirectResponse|DocHtmlView
*
* @Route(
* "",
* name = self::ROUTES__MAIN,
* )
*/
public function mainAction(Request $request): RedirectResponse|DocHtmlView
{
$form = $this->createFormBuilder()
->add('contact', TextType::class, [
'required' => true,
'attr' => [
'autocomplete' => 'off',
'inputmode' => 'email',
],
'constraints' => [
new NotNull(),
new NotBlank(),
],
])
->add('terms', CheckboxType::class, [
'required' => false,
'constraints' => [
new IsTrue(message: 'In order to proceed, you must agree to the Terms and Conditions and have reviewed the privacy policy.'),
],
])
->add('recaptcha', EWZRecaptchaV3Type::class, [
'constraints' => [
new IsTrueV3(),
],
])
->getForm();
if ($this->handleForm($form)) {
return $this->redirectToRoute(self::ROUTES__NOTICE);
}
return $this->html([
'form' => $form->createView(),
]);
}
/**
* @return DocHtmlView
*
* @Route(
* "/notice",
* name = self::ROUTES__NOTICE,
* )
*/
public function noticeAction(): DocHtmlView
{
return $this->html();
}
}