src/Form/Type/PubliciteType.php line 79

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @author Mehrez Labidi
  5.  */
  6. namespace App\Form\Type;
  7. use App\Form\DataTransformer\MessageTransformer;
  8. use App\Form\Models\Publicite;
  9. use App\Helper\TransProvider;
  10. use App\Services\ManagerEntity\PaysManagers;
  11. use App\Services\TelephoneInternational;
  12. use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
  13. use Symfony\Component\Form\AbstractType;
  14. use Symfony\Component\Form\ChoiceList\ChoiceList;
  15. use Symfony\Component\Form\Extension\Core\Type\{
  16.     ChoiceType,
  17.     TextareaType,
  18.     TextType
  19. };
  20. use App\Validator\Constraints\Emoji;
  21. use Symfony\Component\Form\FormBuilderInterface;
  22. use Symfony\Component\OptionsResolver\OptionsResolver;
  23. class PubliciteType extends AbstractType {
  24.     /**
  25.      * @var TransProvider
  26.      */
  27.     private TransProvider $transProvider;
  28.     /**
  29.      * @var TelephoneInternational
  30.      */
  31.     private TelephoneInternational $telephoneInternational;
  32.     /**
  33.      * @var MessageTransformer
  34.      */
  35.     private MessageTransformer $messageTransformer;
  36.     /**
  37.      * @var PaysManagers
  38.      */
  39.     private PaysManagers $PaysManagers;
  40.     /**
  41.      * @param MessageTransformer     $messageTransformer
  42.      * @param TransProvider          $transProvider
  43.      * @param TelephoneInternational $telephoneInternational
  44.      * @param PaysManagers           $PaysManagers
  45.      */
  46.     public function __construct(MessageTransformer $messageTransformerTransProvider $transProviderTelephoneInternational $telephoneInternationalPaysManagers $PaysManagers) {
  47.         $this->transProvider $transProvider;
  48.         $this->telephoneInternational $telephoneInternational;
  49.         $this->messageTransformer $messageTransformer;
  50.         $this->PaysManagers $PaysManagers;
  51.     }
  52.     /**
  53.      * @param FormBuilderInterface $builder
  54.      * @param array                $options
  55.      * @return void
  56.      */
  57.     public function buildForm(FormBuilderInterface $builder, array $options) {
  58.         $builder
  59.                 ->add('nom'TextType::class)
  60.                 ->add('prenom'TextType::class)
  61.                 ->add('mail'TextType::class)
  62.                 ->add('telephone'TextType::class)
  63.                 ->add(
  64.                         'indicatif',
  65.                         ChoiceType::class,
  66.                         [
  67.                             'choices' => $this->telephoneInternational->listIndicatifChoiceForm(),
  68.                             'attr' => ['class' => 'form-control'],
  69.                             'choice_attr' => function ($key$val$index) {
  70.                                 return ($key == "") ? ['disabled' => 'disabled'] : [];
  71.                             },
  72.                             'data' => array_values($this->telephoneInternational->listIndicatifChoiceForm())[0],
  73.                         ]
  74.                 )
  75.                 ->add('societe'TextType::class)
  76.                 ->add('budget'TextType::class,
  77.                         array(
  78.                             'attr' => array(
  79.                                 'placeholder' => $this->transChoice('en') . " " $this->PaysManagers->getSigleDeviseByCodePays($_SESSION['codePays'])
  80.                             )
  81.                         )
  82.                 )
  83.                 ->add('duree'TextType::class,
  84.                         array(
  85.                             'attr' => array(
  86.                                 'placeholder' => $this->transChoice('en mois')
  87.                             )
  88.                         )
  89.                 )
  90.                 ->add('interesse_par'ChoiceType::class, [
  91.                     'choices' => $this->transChoice(FormChoices::publiciteInteressePar(), """M"),
  92.                     'expanded' => true,
  93.                     'multiple' => true'label_html' => true,
  94.                 ])
  95.                 ->add('commentaire',
  96.                         TextareaType::class,
  97.                         [
  98.                             "required" => false,
  99.                             "constraints" => [
  100.                                 new Emoji()
  101.                             ],
  102.                             "attr" => [
  103.                                 "autocomplete" => "off",
  104.                                 "rows" => 8
  105.                             ]
  106.                         ]
  107.                 )
  108.                 ->addViewTransformer($this->messageTransformertrue)
  109.                 ->add('recaptcha'EWZRecaptchaType::class,
  110.                         ['mapped' => false'language' => $this->transProvider->getLocale()]
  111.         );
  112.     }
  113.     /**
  114.      * @param OptionsResolver $resolver
  115.      * @return void
  116.      */
  117.     public function configureOptions(OptionsResolver $resolver) {
  118.         $resolver->setDefaults([
  119.             'data_class' => Publicite::class,
  120.             'csrf_protection' => false,
  121.             'allow_extra_fields' => true,
  122.         ]);
  123.     }
  124.     /**
  125.      * @return string
  126.      */
  127.     public function getBlockPrefix() { // pour unifier avec les inputs definis dans html
  128.         return 'form';
  129.     }
  130.     /**
  131.      * @param $var
  132.      * @return mixed|string
  133.      */
  134.     private function transChoice($var$context ""$majMin "") {
  135.         if (is_string($var)) {
  136.             $var $this->transProvider
  137.                     ->translate($var$context$majMin);
  138.         }
  139.         if (is_array($var)) {
  140.             foreach ($var as $key => $item) {
  141.                 unset($var[$key]);
  142.                 $key $this->transProvider
  143.                         ->translate($key$context$majMin);
  144.                 $var[$key] = $item;
  145.             }
  146.         }
  147.         return $var;
  148.     }
  149. }