src/Form/Type/UserRegistrationType.php line 86

  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('user.register.terms'),
  136.                         'required' => true,
  137.                         'mapped' => false,
  138.                         'constraints' => array(new IsTrue()),
  139.                     )
  140.             )
  141.             ->add('plainPassword'RepeatedType::class, array(
  142.                 'type' => PasswordType::class,
  143.                 'options' => array('translation_domain' => 'FOSUserBundle'),
  144.                 'first_options' => array(
  145.                     'label' => 'form.password',
  146.                     'attr' =>array(
  147.                         'placeholder' => 'Contraseña'
  148.                     )
  149.                 ),
  150.                 'second_options' => array(
  151.                     'label' => 'form.password_confirmation',
  152.                     'attr' =>array(
  153.                         'placeholder' => 'Repita la contraseña*'
  154.                         )
  155.                     )
  156.                 )
  157.             )
  158.             ->add('idCard'HiddenType::class, array(
  159.                     'label'     => 'Numero de documento',
  160.                     'attr'      => array(
  161.                         'placeholder' => 'Numero de documento',
  162.                         'required' => true,
  163.                     )
  164.                 )
  165.             )
  166.             ->add('tipoDocumento',EntityType::class, array(
  167.                     'class'     => 'App\Entity\TipoDocumento',
  168.                     'choice_label' => function ($tipoDocumento) {
  169.                         return $tipoDocumento->getNombre();
  170.                     },
  171.                     'label'     => $options['sm']->getValue('profile.card.idTypeLabel'),
  172.                     'attr'      => array(
  173.                         'placeholder' => 'Selecciona documento',
  174.                         'required' => false,
  175.                     )
  176.             ))
  177.             ->add('fechaCaducidad'DateType::class, array(
  178.                     'widget'    => 'single_text',
  179.                     'html5'     => true,
  180. //                     'format'    => 'dd-MM-yyyy',
  181.                     'label'     =>  $options['sm']->getValue('user.expiredDate'),
  182.                     'attr'      => array(
  183.                         'placeholder' => 'Fecha de caducidad',
  184.                         'class'=>'form-control input-inline datepicker',
  185.                         'data-provide' => 'datepicker',
  186.                         'data-date-format' => 'dd-mm-yyyy',
  187.                         'required' => false,
  188.                     )
  189.             ))
  190.             ->add('fechaNacimiento'DateType::class, array(
  191.                     'widget'    => 'single_text',
  192.                     'html5'     => true,
  193. //                     'format'    => 'dd-MM-yyyy',
  194.                     'label'     => $options['sm']->getValue('profile.card.bornLabel'),
  195.                     'attr'      => array(
  196.                         'placeholder' => 'Fecha de nacimiento',
  197.                         'class'=>'form-control input-inline datepicker',
  198.                         'data-provide' => 'datepicker',
  199.                         'data-date-format' => 'dd-mm-yyyy',
  200.                         'required' => false,
  201.                     )
  202.             ))
  203. //            ->add('newsletterSub', 'checkbox',array(
  204. //                    'label' => 'Quiero suscribirme a las noticias',
  205. //                    'mapped'=> false,
  206. //                    'required' =>false,
  207. //                    'attr'     => array('checked'   => 'checked'),
  208. //                )
  209. //
  210. //            )
  211.             ->remove('username')    //Remove it from the form because we use the e-mail as username
  212.             ;
  213.     }
  214.     
  215.     
  216.     
  217.     public function configureOptions(OptionsResolver $resolver)
  218.     {
  219. //         parent::setDefaultOptions($resolver);
  220.         $resolver->setDefaults( array(
  221.                     'data_class'    => 'App\Entity\User',
  222.                     'orderCode'     => null,
  223.                     'email'         => '',
  224.                     'fullName'      => '',
  225.                     'locale'        => null,
  226.                     'em'            => null,
  227.                     'sm'            => null
  228.         ));
  229.     }
  230.     public function getName()
  231.     {
  232.         return 'dinamic_user_registration';
  233.     }
  234. }