src/Form/ProducerType.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Producer;
  4. use App\Entity\Address;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Form\Extension\Core\Type\FileType;
  12. use Symfony\Component\Validator\Constraints\Image;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. use Symfony\Component\Validator\Constraints\Regex;
  15. use Symfony\Component\Form\Extension\Core\Type\TextType;
  16. class ProducerType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options)
  19.     {
  20.         $builder
  21.             ->add('name'null, [
  22.                 'required' => true,
  23.                 'attr' => [
  24.                     'autocomplete' => 'off',
  25.                     'placeholder' => 'select.name',
  26.                 ],
  27.                 'validation_groups' => ['valid-value'],
  28.             ])
  29.             
  30.             ->add('surname'null, [
  31.                 'label'    => 'User.surname',
  32.                 'required' => true,
  33.                 'attr' => [
  34.                     'autocomplete' => 'off',
  35.                     'placeholder' => 'select.surname',
  36.                 ],
  37.                 'validation_groups' => ['valid-value'],
  38.             ])
  39.         
  40.             ->add('cuit'TextType::class, [
  41.                 'attr' => [
  42.                     'data-cleave' => json_encode(['blocks' => [281], 'delimiter' => '-']),
  43.                     'class' => 'form-control',
  44.                     'placeholder' => '01-12345678-9',
  45.                     'autocomplete' => 'off',
  46.                     'maxlength' => 13,
  47.                     'minlength' => 13,
  48.                 ],
  49.                 'label' => 'CUIT',
  50.                 // 'required => true,
  51.                 'constraints' => [
  52.                     new Regex('/\d{2}\-\d{8}\-\d/'),
  53.                 ],
  54.                 'validation_groups' => ['valid-value'],
  55.         ])
  56.             ->add('cuig'null, [
  57.                 'attr' => [
  58.                     'class' => 'form-control',
  59.                     'placeholder' => 'AB001',
  60.                     'autocomplete' => 'off',
  61.                     'maxlength' => 5,
  62.                     'minlength' => 5,
  63.                     'pattern' => '[a-zA-Z]{2}\d{3}'
  64.                 ],
  65.                 // 'required => true,
  66.                 'constraints' => [
  67.                     new NotBlank(),
  68.                     new Regex('/[a-zA-Z]{2}\d{3}/')
  69.                 ],
  70.                 'validation_groups' => ['valid-value'],
  71.             ])
  72.         ->add('renspa'TextType::class, [
  73.                 'attr' => [
  74.                     'data-cleave' => json_encode(['blocks' => [2315,  2], 'delimiter' => '.']),
  75.                     'class' => 'form-control',
  76.                     'placeholder' => '01.001.1.10101/01',
  77.                     'autocomplete' => 'off',
  78.                     'maxlength' => 17,
  79.                     'minlength' => 17,
  80.                 ],
  81.                 // 'required => true,
  82.                 'constraints' => [
  83.                     new Regex('/\d{2}\.\d{3}\.\d{1}\.\d{5}\.\d{2}/'),
  84.                 ],
  85.                 'validation_groups' => ['valid-value'],
  86.         ])
  87.             ->add('picture'FileType   ::class, [
  88.                 'label' => 'Imagen',
  89.                 'mapped' => false,
  90.                 'required' => false,
  91.                 'error_bubbling' => true,
  92.                 'constraints' => [
  93.                     new Image([
  94.                         'maxSize' => '2M',
  95.                         'mimeTypes' => [
  96.                             'image/png',
  97.                             'image/jpg',
  98.                             'image/jpeg',
  99.                         ],
  100.                         'mimeTypesMessage' => 'file.image.error',
  101.                     ])
  102.                 ]
  103.             ])
  104.             ->add('email'EmailType::class, [
  105.                 'required' => false,
  106.                 'attr' => [
  107.                     'class' => 'form-control',
  108.                     'autocomplete' => 'off',
  109.                     'placeholder' => 'select.email'
  110.                 ]
  111.             ])
  112.             ->add('businessName'null, [
  113.                 'required' => false,
  114.                 'attr' => [
  115.                     'class' => 'form-control',
  116.                     'autocomplete' => 'off',
  117.                     'placeholder' => 'select.businessName',
  118.                 ],
  119.                 'label' => 'Producer.businessName',
  120.             ])
  121.             ->add('phone'null, [
  122.                 'required' => false,
  123.                 'attr' => [
  124.                     'class' => 'form-control',
  125.                     'autocomplete' => 'off',
  126.                     'placeholder' => 'select.phone',
  127.                 ],
  128.                 'label' => 'Producer.phone'
  129.             ])
  130.             ->add('address'TextType::class, [
  131.                 'required' => false,
  132.                 'attr' => [
  133.                     'data-selectize'=>'{"valueField":"id","labelField":"name", "searchField":"name", "delimiter": "|"}',
  134.                     'class' => 'filters selectize geocode','placeholder' => 'select.addressChoice'],
  135.                 'label' => 'Form.addressLabel',
  136.             ])
  137.         ;
  138.     }
  139.     public function configureOptions(OptionsResolver $resolver)
  140.     {
  141.         $resolver->setDefaults([
  142.             'data_class' => Producer::class,
  143.             'validation_groups' => ['valid-value'],
  144.         ]);
  145.     }
  146. }