src/Form/Type/CabeceraType.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Form\Type;
  3. use App\Entity\Cabecera;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  10. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13. use Symfony\Component\Form\FormEvent;
  14. use Symfony\Component\Form\FormEvents;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. use Symfony\Component\Validator\Constraints\Type;
  18. class CabeceraType extends AbstractType
  19. {
  20.     public function buildForm(FormBuilderInterface $builder, array $options): void
  21.     {
  22.         $builder
  23.             // ->add('nombrecliente', TextType::class)
  24.             ->add('nombres'TextType::class)
  25.             ->add('apellidos'TextType::class, ['required' => false])
  26.             ->add('sucursal'HiddenType::class)
  27.             ->add('direccioncliente'TextType::class)
  28.             ->add('direccion2cliente'TextType::class, ['required' => false])
  29.             ->add('tipodeservicio'ChoiceType::class, [
  30.                 'choices' => Cabecera::SERVICE_TYPE,
  31.                 'expanded' => true,
  32.                 'multiple' => false,
  33.             ])
  34.             ->add('telefonocliente'TextType::class, [
  35.                 'constraints' => [
  36.                     new Type([
  37.                         'type'    => 'numeric',
  38.                         'message' => 'El teléfono debe ser numérico',
  39.                     ]),
  40.                 ],
  41.             ])
  42.             ->add('nifcliente'TextType::class, [
  43.                 'required' => false,
  44.                 'constraints' => [
  45.                     new Type([
  46.                         'type'    => 'numeric',
  47.                         'message' => 'El documento debe ser numérico',
  48.                     ]),
  49.                 ],
  50.             ])
  51.             ->add('emailcliente'EmailType::class, ['required' => false])
  52.             // ->add('facturaelectronica', CheckboxType::class, [
  53.             //     'label'    => 'Factura Electrónica',
  54.             //     'required' => false,
  55.             // ])
  56.             ->add('nombre_receptor'TextType::class, ['required' => false'label' => 'Nombre del que recibe'])
  57.             ->add('telefono_receptor'TextType::class, ['required' => false'label' => 'telefono del que recibe'])
  58.             // ->add('observaciones_receptor', TextareaType::class, ['required' => false, 'label' => 'observaciones'])
  59.             ->add('save'SubmitType::class, ['label' => 'Continuar']);
  60.         if (!$options['editable_mode']) {
  61.             $builder->get('nombres')->setDisabled(true);
  62.             $builder->get('apellidos')->setDisabled(true);
  63.             $builder->get('nifcliente')->setDisabled(true);
  64.             $builder->get('emailcliente')->setDisabled(true);
  65.             $builder->get('telefonocliente')->setDisabled(true);
  66.         }
  67.         // else {
  68.         //     $builder->remove('facturaelectronica');
  69.         // }
  70.         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  71.             $cab $event->getData();
  72.             $form $event->getForm();
  73.             if (null === $cab->getFechareserva()) {
  74.                 $form->add('fechareserva'DateTimeType::class, [
  75.                     'date_widget' => 'single_text',
  76.                     'data' => new \DateTime(),
  77.                     'hours' => range(722),
  78.                     'minutes' => array(000510152025303540455055),
  79.                 ]);
  80.             } else {
  81.                 $form->add('fechareserva'DateTimeType::class, [
  82.                     'date_widget' => 'single_text',
  83.                     'hours' => range(722),
  84.                     'minutes' => array(000510152025303540455055),
  85.                 ]);
  86.             }
  87.         });
  88.         // $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  89.         //     $cab = $event->getData();
  90.         //     $form = $event->getForm();
  91.         //     // checks if the Product object is "new"
  92.         //     // If no data is passed to the form, the data is "null".
  93.         //     // This should be considered a new "Product"
  94.         //     if (null === $cab->getFechareserva()) {
  95.         //         $form->add('name', TextType::class);
  96.         //     }
  97.         // });
  98.     }
  99.     public function configureOptions(OptionsResolver $resolver): void
  100.     {
  101.         $resolver->setDefaults([
  102.             'data_class' => Cabecera::class,
  103.             'editable_mode' => true,
  104.         ]);
  105.     }
  106. }