src/Form/Type/UserRegistrationType.php line 177

  1. <?php
  2. namespace App\Form\Type;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\OptionsResolver\OptionsResolver;
  6. use FOS\UserBundle\Form\Type\RegistrationFormType;
  7. use Symfony\Component\Validator\Constraints\IsTrue;
  8. use App\Entity\User;
  9. use App\Entity\Pais;
  10. use Symfony\Component\Form\AbstractType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  13. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  14. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  15. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  16. use Symfony\Component\Form\Extension\Core\Type\DateType;
  17. use Symfony\Component\Form\Extension\Core\Type\FileType;
  18. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  19. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  20. use Doctrine\ORM\EntityRepository;
  21. class UserRegistrationType extends AbstractType
  22. {
  23. //     protected $locale;
  24. //     protected $request;
  25. // 
  26. //     public function __construct($locale)
  27. //     {
  28. //         $this->locale=$locale;
  29. //     }
  30.     public function getParent()
  31.     {
  32.         return RegistrationFormType::class;
  33.     }
  34.     public function buildForm(FormBuilderInterface $builder, array $options)
  35.     {
  36.         parent::buildForm($builder$options);
  37.         $locale $options['locale'];
  38.         $em $options['em'];
  39. //         $fullName = $options['fullName'];
  40. //         $email = $options['email'];
  41. //         $orderCode = $options['orderCode'];
  42.         $builder
  43.             ->add('name'TextType::class, array(
  44.                     'label'     => $options['sm']->getValue('profile.card.nameLabel'),
  45.                     'attr'      => array(
  46.                         'placeholder' => 'Nombre Completo',
  47.                         'required' => true,
  48.                     )
  49.                 )
  50.             )
  51.             ->add('idCard'TextType::class, array(
  52.                     'label'     => $options['sm']->getValue('profile.card.nameLabel'),
  53.                     'attr'      => array(
  54.                         'placeholder' => 'Numero del cocumento',
  55.                         'required' => true,
  56.                     )
  57.                 )
  58.             )
  59.             ->add('email'TextType::class, array(
  60.                     'label'     => $options['sm']->getValue('page.business.emailForm'),
  61.                     'data'      => null/*$email*/,
  62.                     'attr'      => array(
  63.                         'placeholder' => 'E-mail',
  64.                     )
  65.                 )
  66.             )
  67.             ->add('telefono'TextType::class, array(
  68.                     'label'     => $options['sm']->getValue('user.phone'),
  69.                     'data'      => null/*$email*/,
  70.                     'attr'      => array(
  71.                         'placeholder' => 'Teléfono',
  72.                     )
  73.                 )
  74.             )
  75.             ->add('pais',EntityType::class, array(
  76.                     'class'     => 'App\Entity\Pais',
  77.                     'label'     => $options['sm']->getValue('profile.address.country'),
  78.                     'placeholder' => 'Selecciona un país',
  79.                     'choice_attr' => function ($pais) {
  80.                             return ['data-iso' => $pais->getIso3()];
  81.                     },
  82.             ))
  83.             ->add('direccion1'TextType::class, array(
  84.                     'label'     => $options['sm']->getValue('profile.address.label1'),
  85.                     'attr'      => array(
  86.                         'placeholder' => 'Direccion completa',
  87.                         'maxlength' => 50
  88.                     )
  89.                 )
  90.             )
  91.             ->add('ciudad'TextType::class, array(
  92.                     'label'     => $options['sm']->getValue('profile.address.city'),
  93.                     'attr'      => array(
  94.                         'placeholder' => 'Población',
  95.                     )
  96.                 )
  97.             )
  98.             ->add('county'TextType::class, array(
  99.                     'label'     => $options['sm']->getValue('profile.address.region'),
  100.                     'attr'      => array(
  101.                         'placeholder' => 'Provincia',
  102.                     )
  103.                 )
  104.             )
  105.             ->add('cp'TextType::class, array(
  106.                     'label'     => $options['sm']->getValue('profile.address.pc'),
  107.                     'attr'      => array(
  108.                         'placeholder' => 'Código postal',
  109.                     )
  110.                 )
  111.             )
  112.             ->add('urlImagen'FileType::class, array(
  113. //                          'label' => false,
  114.                 'label' => $options['sm']->getValue('profile.card.ImgLabel'),
  115.                 'data_class' => 'Symfony\Component\HttpFoundation\File\File',
  116.                 "attr" =>array("class" => "form-control"),
  117.                 'validation_groups' => ['create'],
  118.                 'required' => false,
  119.             ))
  120.             ->add('urlImagenCheckbox'CheckboxType::class, array(
  121.                 'label' => $options['sm']->getValue('profile.card.parte_trasera'),
  122.                 'required' => false,
  123.                 'mapped' => false,
  124.             ))
  125.             ->add('urlImagen2'FileType::class, array(
  126.                 'label' => $options['sm']->getValue('profile.card.traseraa'),
  127.                 'required' => false,
  128.                 'data_class' => 'Symfony\Component\HttpFoundation\File\File',
  129.                 "attr" =>array('class' => "form-control-trasero hidden",
  130.                     'placeholder' => "Parte trasera"
  131.                 ),
  132.                 'validation_groups' => ['create'],
  133.             ))
  134.             ->add('privacy_policy_consent'CheckboxType::class, array(
  135.                         'label' => $options['sm']->getValue('acepto.terms').' <a href="'.$options['sm']->getValue('enlace.politica.privacidad').'" target="_blank">'.$options['sm']->getValue('webmap.privacy_policy').'</a>',
  136.                         'required' => true,
  137.                         'mapped' => false,
  138.                         'label_html' => true,
  139.                         'constraints' => array(new IsTrue()),
  140.                     )
  141.             )
  142.             ->add('plainPassword'RepeatedType::class, array(
  143.                 'type' => PasswordType::class,
  144.                 'options' => array('translation_domain' => 'FOSUserBundle'),
  145.                 'first_options' => array(
  146.                     'label' => 'form.password',
  147.                     'attr' =>array(
  148.                         'placeholder' => 'Contraseña'
  149.                     )
  150.                 ),
  151.                 'second_options' => array(
  152.                     'label' => 'form.password_confirmation',
  153.                     'attr' =>array(
  154.                         'placeholder' => 'Repita la contraseña*'
  155.                         )
  156.                     )
  157.                 )
  158.             )
  159.             ->add('idCard'HiddenType::class, array(
  160.                     'label'     => 'Numero de documento',
  161.                     'attr'      => array(
  162.                         'placeholder' => 'Numero de documento',
  163.                         'required' => true,
  164.                     )
  165.                 )
  166.             )
  167.             ->add('tipoDocumento',EntityType::class, array(
  168.                     'class'     => 'App\Entity\TipoDocumento',
  169.                     'choice_label' => function ($tipoDocumento) {
  170.                         return $tipoDocumento->getNombre();
  171.                     },
  172.                     'label'     => $options['sm']->getValue('profile.card.idTypeLabel'),
  173.                     'attr'      => array(
  174.                         'placeholder' => 'Selecciona documento',
  175.                         'required' => false,
  176.                     )
  177.             ))
  178.             ->add('fechaCaducidad'DateType::class, array(
  179.                     'widget'    => 'single_text',
  180.                     'html5'     => true,
  181. //                     'format'    => 'dd-MM-yyyy',
  182.                     'label'     =>  $options['sm']->getValue('user.expiredDate'),
  183.                     'attr'      => array(
  184.                         'placeholder' => 'Fecha de caducidad',
  185.                         'class'=>'form-control input-inline datepicker',
  186.                         'data-provide' => 'datepicker',
  187.                         'data-date-format' => 'dd-mm-yyyy',
  188.                         'required' => false,
  189.                     )
  190.             ))
  191.             ->add('fechaNacimiento'DateType::class, array(
  192.                     'widget'    => 'single_text',
  193.                     'html5'     => true,
  194. //                     'format'    => 'dd-MM-yyyy',
  195.                     'label'     => $options['sm']->getValue('profile.card.bornLabel'),
  196.                     'attr'      => array(
  197.                         'placeholder' => 'Fecha de nacimiento',
  198.                         'class'=>'form-control input-inline datepicker',
  199.                         'data-provide' => 'datepicker',
  200.                         'data-date-format' => 'dd-mm-yyyy',
  201.                         'required' => false,
  202.                     )
  203.             ))
  204. //            ->add('newsletterSub', 'checkbox',array(
  205. //                    'label' => 'Quiero suscribirme a las noticias',
  206. //                    'mapped'=> false,
  207. //                    'required' =>false,
  208. //                    'attr'     => array('checked'   => 'checked'),
  209. //                )
  210. //
  211. //            )
  212.             ->remove('username')    //Remove it from the form because we use the e-mail as username
  213.             ;
  214.     }
  215.     
  216.     
  217.     
  218.     public function configureOptions(OptionsResolver $resolver)
  219.     {
  220. //         parent::setDefaultOptions($resolver);
  221.         $resolver->setDefaults( array(
  222.                     'data_class'    => 'App\Entity\User',
  223.                     'orderCode'     => null,
  224.                     'email'         => '',
  225.                     'fullName'      => '',
  226.                     'locale'        => null,
  227.                     'em'            => null,
  228.                     'sm'            => null
  229.         ));
  230.     }
  231.     public function getName()
  232.     {
  233.         return 'dinamic_user_registration';
  234.     }
  235. }