src/Form/ProfileType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Profile;
  4. use App\Entity\AnimalSpecie;
  5. use Symfony\Component\Form\AbstractType;
  6. use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\EntityFilterType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. use Symfony\Component\Validator\Constraints\Regex;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. class ProfileType extends AbstractType
  16. {
  17.     /* @var TranslatorInterface $translator */
  18.     private $translator;
  19.     public function __construct(TranslatorInterface $translator)
  20.     {
  21.         $this->translator $translator;
  22.     }
  23.     public function buildForm(FormBuilderInterface $builder, array $options)
  24.     {
  25.         $_ $this->translator;
  26.         $builder
  27.             ->add('name'null
  28.             [
  29.                 'attr' => [
  30.                     'placeholder' => 'Name',
  31.                 ],
  32.                 'required' => true,
  33.                 'empty_data' => '',
  34.                 // 'validation_groups' => ['valid-value'],
  35.             ])
  36.             ->add('cuit'TextType::class, [
  37.                 'attr' => [
  38.                     'data-cleave' => json_encode(['blocks' => [281], 'delimiter' => '-']),
  39.                     'class' => 'form-control',
  40.                     'placeholder' => '01-12345678-9',
  41.                     'autocomplete' => 'off',
  42.                     'maxlength' => 13,
  43.                     'minlength' => 13,
  44.                 ],
  45.                 'label' => 'Cuit',
  46.                 'required' => true,
  47.                 'constraints' => [
  48.                     new Regex('/\d{2}\-\d{8}\-\d/'),
  49.                 ],
  50.                 // 'validation_groups' => ['valid-value'],
  51.             ])
  52.         ->add('entityName')
  53.             ->add('otherCity')
  54.             ->add('otherName')
  55.             ->add('otherEmail')
  56.             ->add('otherState')
  57.             ->add('timeZone'TimezoneType::class, [
  58.                 'attr' => [ 'class' => 'selectize'],
  59.                 'label' => 'User.timeZone',
  60.                 'empty_data' => 'America/Argentina/Buenos_Aires',
  61.             ])
  62.         ->add('surname'null,
  63.         [
  64.             'attr' => [
  65.                 'placeholder' => $_->trans('select.surname'),
  66.             ],
  67.             'required' => true,
  68.             'empty_data' => '',
  69.             'label' => 'User.surname',
  70.             // 'validation_groups' => ['valid-value'],
  71.         ])
  72.         ->add('middleName'null,
  73.         [
  74.              'attr' => [
  75.                    'placeholder' => $_->trans('select.middleName'),
  76.                 ],
  77.                 'empty_data' => '',
  78.                 'label' => 'User.middleName',
  79.             ])
  80.         ->add('language'ChoiceType::class, [
  81.             'attr' => ['class' => 'selectize'],
  82.                 'label' => 'User.locale',
  83.                 'choices' => [
  84.                     'Español' => 'es',
  85.                     'Inglés' => 'en',
  86.                     'Portugués' => 'pt',
  87.             ],
  88.             'empty_data' => 'es',
  89.         ])
  90.         ->add('defaultAnimalSpecie'EntityFilterType::class, [/*{{{*/
  91.                 'required' => true,
  92.                 'label' => 'Form.defaultAnimalSpecie',
  93.                 'attr' => ['class' => 'filters selectize','placeholder' =>'select.animalSpecie'],
  94.                 'class' => AnimalSpecie::class,
  95.                 'query_builder' => function ( $repository ) { return $repository->entryHelp(); }
  96.             ])/*}}}*/
  97.         ;
  98.     }
  99.     public function configureOptions(OptionsResolver $resolver)
  100.     {
  101.         $resolver->setDefaults([
  102.             'data_class' => Profile::class,
  103.             // 'validation_groups' => ['valid-value'],
  104.         ]);
  105.     }
  106. }