src/Twig/Components/Common/CallbackForm.php line 14

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Twig\Components\Common;
  4. use App\Form\RequestConsultationType;
  5. use Symfony\Component\Form\FormFactoryInterface;
  6. use Symfony\Component\Form\FormView;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
  9. #[AsTwigComponent]
  10. class CallbackForm
  11. {
  12.     private ?string $urlToPrivacyPolicy;
  13.     private ?bool $displayIAgreeBlock;
  14.     private ?string $formType null;
  15.     private ?string $forService null;
  16.     private FormView $requestConsultationForm;
  17.     public function __construct(
  18.         private readonly FormFactoryInterface $formFactory,
  19.         private readonly RequestStack $requestStack,
  20.     ) {
  21.     }
  22.     /**
  23.      * @return string[]
  24.      */
  25.     private function getFormTypes(): array
  26.     {
  27.         return [
  28.             'default',
  29.             'main',
  30.             'main-double',
  31.             'advanced',
  32.             'advanced-with-name''main-2',
  33.             'advanced-with-name-v2',
  34.             'advanced-with-name-v3'
  35.         ];
  36.     }
  37.     /**
  38.      * @param string|null $urlToPrivacyPolicy
  39.      * @param bool|null   $displayIAgreeBlock
  40.      * @param string|null $formType
  41.      * @param string|null $forService
  42.      *
  43.      * @return void
  44.      */
  45.     public function mount(
  46.         ?string $urlToPrivacyPolicy null,
  47.         ?bool $displayIAgreeBlock false,
  48.         ?string $formType null,
  49.         ?string $forService null,
  50.     ): void {
  51.         $this->urlToPrivacyPolicy $urlToPrivacyPolicy;
  52.         $this->displayIAgreeBlock $displayIAgreeBlock;
  53.         if (in_array($formType$this->getFormTypes())) {
  54.             $this->formType $formType;
  55.         }
  56.         if (in_array($forService, ['default''notary''appraiser''lawyer'])) {
  57.             $this->forService $forService;
  58.         }
  59.         $request $this->requestStack->getCurrentRequest();
  60.         $form $this->formFactory->create(RequestConsultationType::class);
  61.         $form->handleRequest($request);
  62.         if ($form->isSubmitted() && $form->isValid()) {
  63.         }
  64.         $this->requestConsultationForm $form->createView();
  65.     }
  66.     public function getUrlToPrivacyPolicy(): ?string
  67.     {
  68.         return $this->urlToPrivacyPolicy;
  69.     }
  70.     public function getDisplayIAgreeBlock(): ?bool
  71.     {
  72.         return $this->displayIAgreeBlock;
  73.     }
  74.     public function getFormType(): ?string
  75.     {
  76.         return $this->formType;
  77.     }
  78.     public function getForService(): ?string
  79.     {
  80.         return $this->forService;
  81.     }
  82.     public function getRequestConsultationForm(): FormView
  83.     {
  84.         return $this->requestConsultationForm;
  85.     }
  86. }