src/Form/Type/DemandeFinancementType.php line 79

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * @author Mehrez Labidi
  4.  */
  5. namespace App\Form\Type;
  6. use App\Form\DataTransformer\MessageTransformer;
  7. use App\Form\Models\DemandeFinancement;
  8. use App\Helper\TransProvider;
  9. use App\Helper\Utils;
  10. use App\Services\TelephoneInternational;
  11. use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
  12. use Symfony\Component\Form\AbstractType;
  13. use Symfony\Component\Form\ChoiceList\ChoiceList;
  14. use Symfony\Component\Form\Extension\Core\Type\{ChoiceType,DateType,TextareaType,TextType  };
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. class DemandeFinancementType extends AbstractType
  18. {
  19.     /**
  20.      * @var MessageTransformer
  21.      */
  22.     private $messageTransformer;
  23.     /**
  24.      * @var TelephoneInternational
  25.      */
  26.     private $telephoneInternational;
  27.     /**
  28.      * @var TransProvider
  29.      */
  30.     private $transProvider;
  31.     /**
  32.      * @param TransProvider          $transProvider
  33.      * @param MessageTransformer     $messageTransformer
  34.      * @param TelephoneInternational $telephoneInternational
  35.      */
  36.     public function __construct(TransProvider $transProviderMessageTransformer $messageTransformerTelephoneInternational $telephoneInternational)
  37.     {
  38.         $this->transProvider $transProvider;
  39.         $this->messageTransformer $messageTransformer;
  40.         $this->telephoneInternational $telephoneInternational;
  41.     }
  42.     /**
  43.      * @param FormBuilderInterface $builder
  44.      * @param array                $options
  45.      * @return void
  46.      */
  47.     public function buildForm(FormBuilderInterface $builder, array $options)
  48.     {
  49.         $builder
  50.             ->add('civilite'ChoiceType::class, [
  51.                 'choices' => $this->transChoice(FormChoices::civilite()),
  52.                 'expanded' => true,
  53.                 'multiple' => false,
  54.             ])
  55.             ->add('nom'TextType::class,
  56.                 ['attr' => ['id' => 'nom']]
  57.             )
  58.             ->add('prenom'TextType::class,
  59.                 ['attr' => ['id' => 'prenom']]
  60.             )
  61.             ->add('code_postal_utilisateur'TextType::class,
  62.                 ['attr' => ['id' => 'code_postal_utilisateur']]
  63.             )
  64.             ->add('email'TextType::class,
  65.                 ['attr' => ['id' => 'email']]
  66.             )
  67.             ->add('telephone'TextType::class,
  68.                 ['attr' => ['id' => 'telephone']]
  69.             )
  70.             ->add('indicatif',ChoiceType::class,
  71.                 [
  72.                     'choices' => $this->telephoneInternational->listIndicatifChoiceForm(),
  73.                            'attr' => [  'class' => 'form-control'],
  74.                     'choice_attr' => function ($key$val$index) {
  75.                         return ($key == "") ? ['disabled' => 'disabled'] : [];
  76.                     },
  77.                     'data' =>Utils::firstValInArray($this->telephoneInternational->listIndicatifChoiceForm()) ,
  78.                 ]
  79.             )
  80.             ->add('montant_apport'TextType::class,
  81.                 ['attr' => ['id' => 'montant_apport']]
  82.             )
  83.             ->add('activite_societe'TextareaType::class,
  84.                 ['attr' => ['id' => 'activite_societe']]
  85.             )->addViewTransformer($this->messageTransformertrue)
  86.             ->add('ca'TextType::class,
  87.                 ['attr' => ['id' => 'ca']]
  88.             )
  89.             ->add('resultat_net'TextType::class,
  90.                 ['attr' => ['id' => 'resultat_net']]
  91.             )
  92.             ->add('code_postal_siege'TextType::class,
  93.                 ['attr' => ['id' => 'code_postal_siege']]
  94.             )
  95.             ->add('date_realisation_operation'DateType::class,
  96.                [
  97.                    'widget' => 'single_text'
  98.                ]
  99.             )
  100.             ->add('montant_a_financer'TextType::class,
  101.                 ['attr' => ['id' => 'montant_a_financer']]
  102.             )
  103.             ->add('banque_actuelle'TextType::class,
  104.                 ['attr' => ['id' => 'banque_actuelle']]
  105.             )
  106.             ->add('diponibilites',
  107.                 ChoiceType::class,
  108.                 [
  109.                     'choices' => $this->transChoice(FormChoices::disponibilites())
  110.                 ]
  111.             )
  112.             ->add('commentaires'TextareaType::class,
  113.                     [
  114.                         'attr' => ['row' => '8']
  115.                     ]
  116.             )
  117.             ->addViewTransformer($this->messageTransformertrue)
  118.             ->add('recaptcha'EWZRecaptchaType::class,
  119.                 ['mapped' => false,'language' => $this->transProvider->getLocale()]
  120.             );
  121.     }
  122.     /**
  123.      * @param $var
  124.      * @return mixed|string
  125.      */
  126.     private function transChoice($var)
  127.     {
  128.         if (is_string($var)) {
  129.             $var $this->transProvider
  130.                 ->translate($var"""M");
  131.         }
  132.         if (is_array($var)) {
  133.             foreach ($var as $key => $item) {
  134.                 unset($var[$key]);
  135.                 $key $this->transProvider
  136.                     ->translate($key"""M");
  137.                 $var[$key] = $item;
  138.             }
  139.         }
  140.         return $var;
  141.     }
  142.     /**
  143.      * @param OptionsResolver $resolver
  144.      * @return void
  145.      */
  146.     public function configureOptions(OptionsResolver $resolver)
  147.     {
  148.         $resolver->setDefaults([
  149.             'data_class' => DemandeFinancement::class,
  150.             'csrf_protection' => false,
  151.             'allow_extra_fields' => true,
  152.         ]);
  153.     }
  154.     /**
  155.      * @return string
  156.      */
  157.     public function getBlockPrefix()
  158.     { // pour unifier avec les inputs definis dans html
  159.         return 'form';
  160.     }
  161. }