<?php
declare(strict_types=1);
namespace App\Twig\Components\Common;
use App\Form\RequestConsultationType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent]
class CallbackForm
{
private ?string $urlToPrivacyPolicy;
private ?bool $displayIAgreeBlock;
private ?string $formType = null;
private ?string $forService = null;
private FormView $requestConsultationForm;
public function __construct(
private readonly FormFactoryInterface $formFactory,
private readonly RequestStack $requestStack,
) {
}
/**
* @return string[]
*/
private function getFormTypes(): array
{
return [
'default',
'main',
'main-double',
'advanced',
'advanced-with-name', 'main-2',
'advanced-with-name-v2',
'advanced-with-name-v3'
];
}
/**
* @param string|null $urlToPrivacyPolicy
* @param bool|null $displayIAgreeBlock
* @param string|null $formType
* @param string|null $forService
*
* @return void
*/
public function mount(
?string $urlToPrivacyPolicy = null,
?bool $displayIAgreeBlock = false,
?string $formType = null,
?string $forService = null,
): void {
$this->urlToPrivacyPolicy = $urlToPrivacyPolicy;
$this->displayIAgreeBlock = $displayIAgreeBlock;
if (in_array($formType, $this->getFormTypes())) {
$this->formType = $formType;
}
if (in_array($forService, ['default', 'notary', 'appraiser', 'lawyer'])) {
$this->forService = $forService;
}
$request = $this->requestStack->getCurrentRequest();
$form = $this->formFactory->create(RequestConsultationType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
}
$this->requestConsultationForm = $form->createView();
}
public function getUrlToPrivacyPolicy(): ?string
{
return $this->urlToPrivacyPolicy;
}
public function getDisplayIAgreeBlock(): ?bool
{
return $this->displayIAgreeBlock;
}
public function getFormType(): ?string
{
return $this->formType;
}
public function getForService(): ?string
{
return $this->forService;
}
public function getRequestConsultationForm(): FormView
{
return $this->requestConsultationForm;
}
}