<?php
namespace App\Form\User;
use App\Model\User\Additionnal;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
class AddInformationType extends AbstractType
{
private RequestStack $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$session = $this->requestStack->getSession();
$hasAdditional = $session->get('hasAdditionalInformation');
if (empty($hasAdditional)) {
$builder
->add('information', TextType::class, [
'translation_domain' => 'form',
'label'=> false,
]);
} else
$builder
->add('information', TextType::class, [
'translation_domain' => 'form',
'label'=> false,
'constraints' => [
new Assert\NotBlank(['message' => 'La sélection est obligatoire.']),
],
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Additionnal::class,
]);
}
}