<?php
namespace App\Form;
use App\Entity\Inseminateur;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Doctrine\ORM\EntityRepository;
use VictorPrdh\RecaptchaBundle\Form\ReCaptchaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use App\Entity\DicGouvernorat;
use App\Entity\DicCircuit;
class InseminateurType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('nprInsAr', TextType::class, array('required' => false, 'attr' => array('class' => 'form-control form-control-line')))
->add('nprInsFr', TextType::class, array('required' => true, 'attr' => array('class' => 'form-control form-control-line')))
->add('typeIns', TextType::class, array('required' => true, 'attr' => array('class' => 'form-control form-control-line')))
->add('identIns', TextType::class, array('required' => true, 'attr' => array('class' => 'form-control form-control-line')))
->add('adresse', TextType::class, array('required' => true, 'attr' => array('class' => 'form-control form-control-line')))
->add('numTel', TextType::class, array('required' => true, 'attr' => array('class' => 'form-control form-control-line')))
->add('numFax', IntegerType::class, array('required' => false, 'attr' => array('class' => 'form-control form-control-line')))
->add('dicGouvernorat', EntityType::class, [
'class' => DicGouvernorat::class,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('g')
->orderBy('g.gouvernorat', 'ASC');
},
'choice_label' => function ($gouvernorat) use ($options) {
return $options['locale'] == 'fr' ? $gouvernorat->getGouvernorat() : $gouvernorat->getNomAr();
},
'required' => true, 'attr' => array('required' => 'required', 'class' => 'form-control'),
])
->add('dicCircuit', EntityType::class, [
'class' => DicCircuit::class,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c')
->orderBy('c.desCirLt', 'ASC');
},
'choice_label' => function ($dicCircuit) use ($options) {
return $options['locale'] == 'fr' ? $dicCircuit->getDesCirLt() : $dicCircuit->getDesCirLi();
},
'required' => true, 'attr' => array('required' => 'required', 'class' => 'form-control')
])
->add('recaptcha', ReCaptchaType::class,array('attr' => array('required' => 'required')))
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Inseminateur::class,
'locale' => 'fr', // Par défaut en français
]);
}
}