src/Form/AdresseFacturationAbonnementType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Adresse;
  4. use Captcha\Bundle\CaptchaBundle\Form\Type\CaptchaType;
  5. use Captcha\Bundle\CaptchaBundle\Validator\Constraints\ValidCaptcha;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\Extension\Core\Type\DateType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class AdresseFacturationAbonnementType extends AbstractType
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options)
  17.     {
  18.         $adresseExist = isset($options['adresseExist'])?$options['adresseExist']:null;
  19.         $firstName $adresseExist $adresseExist->getFirstname():null;
  20.         $lastName $adresseExist $adresseExist->getLastname():null;
  21.         $conpany $adresseExist $adresseExist->getConpany():null;
  22.         $email $adresseExist $adresseExist->getEmail():null;
  23.         $phone $adresseExist $adresseExist->getPhone():null;
  24.         $adresse null;
  25.         if($adresseExist){
  26.             if(method_exists($adresseExist,'getAdresse')){
  27.                 $adresse =  $adresseExist->getAdresse();
  28.             }else{
  29.                 $adresse =  $adresseExist->getAddress();
  30.             }
  31.         }
  32.         $city $adresseExist $adresseExist->getCity():null;
  33.         $codePostal $adresseExist $adresseExist->getCodePostal():null;
  34.         $batiment $adresseExist $adresseExist->getBatiment():null;
  35.         $lat $adresseExist $adresseExist->getLat():null;
  36.         $longi $adresseExist $adresseExist->getLongi():null;
  37.         $country $adresseExist $adresseExist->getCountry():null;
  38.         $user = isset($options['user']) ? $options['user'] :null;
  39.         $builder
  40.             ->add('firstname',TextType::class,array(
  41.                 'required' => true,
  42.                 'data' => $firstName,
  43.                 'attr' => array(
  44.                     'placeholder' => 'Nom'
  45.                 )
  46.             ))
  47.             ->add('lastname',TextType::class,array(
  48.                 'required' => true,
  49.                 'data' => $lastName,
  50.                 'attr' => array(
  51.                     'placeholder' => 'Prénom'
  52.                 )
  53.             ))
  54.             ->add('conpany',TextType::class,array(
  55.                 'required' => false,
  56.                 'data' => $conpany,
  57.                 'attr' => array(
  58.                     'placeholder' => 'Nom de l\'entreprise'
  59.                 )
  60.             ))
  61.             ->add('phone',TextType::class,array(
  62.                 'data' => $phone,
  63.                 'required' => false
  64.             ))
  65.             ->add('email',TextType::class,array(
  66.                 'required' => true,
  67.                 'data' => $email,
  68.                 'attr' => array(
  69.                     'placeholder' => 'Adresse mail'
  70.                 )
  71.             ))
  72.             ->add('adresse',TextType::class,array(
  73.                 'required' => true,
  74.                 'data' => $adresse,
  75.                 'attr' => array(
  76.                     'placeholder' => 'Adresse'
  77.                 )
  78.             ))
  79.             ->add('city',TextType::class,array(
  80.                 'required' => true,
  81.                 'data' => $city,
  82.                 'attr' => array(
  83.                     'placeholder' => 'Ville'
  84.                 )
  85.             ))
  86.             ->add('codePostal',TextType::class,array(
  87.                 'required' => true,
  88.                 'data' => $codePostal,
  89.                 'attr' => array(
  90.                     'placeholder' => 'Code Postal'
  91.                 )
  92.             ))
  93.             ->add('batiment',TextType::class,array(
  94.                 'required' => false,
  95.                 'data' => $batiment,
  96.                 'attr' => array(
  97.                     'placeholder' => 'Complément d\'adresse'
  98.                 )
  99.             ))
  100.             ->add('lat',HiddenType::class,array('data' => $lat))
  101.             ->add('longi',HiddenType::class,array('data' => $longi))
  102.             ->add('country',HiddenType::class,array('data' => $country))
  103.             ->add('secteurActivite'ChoiceType::class, [
  104.                 'choices' => [
  105.                     'Technologie' => 'Technologie',
  106.                     'Agroalimentaire' => 'Agroalimentaire',
  107.                     'Textile' => 'Textile',
  108.                     'Finance et assurance' => 'Finance et assurance',
  109.                     'Energie' => 'Energie',
  110.                     'Service' => 'Service',
  111.                     'Education' => 'Education',
  112.                     'Santé' => 'Santé',
  113.                     'Formation' => 'Formation',
  114.                     'Hotellerie restauration' => 'Hotellerie restauration',
  115.                     'Autres' => 'Autres'
  116.                 ],
  117. //                'placeholder' => 'Technologie',
  118.             ])
  119.             ->add('captchaCode'CaptchaType::class, array(
  120.                         'captchaConfig' => 'ExampleCaptcha',
  121.                         'label' => 'Retype the characters from the picture',
  122.                          'constraints' => [ new ValidCaptcha(['message' => 'Captcha invalide.'])]
  123.                     ))
  124.                 ;
  125.     }
  126.     public function configureOptions(OptionsResolver $resolver)
  127.     {
  128.         $resolver->setDefaults([
  129.             'data_class' => Adresse::class,
  130.             'adresseExist' => null,
  131.             'allow_extra_fields' => true
  132.         ]);
  133.     }
  134. }