src/Form/HtFileType.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Client;
  4. use App\Entity\ClientContact;
  5. use App\Entity\HtFile;
  6. use App\Entity\Supplier;
  7. use App\Helper\StatusHelper;
  8. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  9. use Symfony\Component\Form\AbstractType;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  12. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  13. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  14. use Symfony\Component\Form\Extension\Core\Type\TelType;
  15. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  16. use Symfony\Component\Form\Extension\Core\Type\TextType;
  17. use Symfony\Component\Form\FormBuilderInterface;
  18. use Symfony\Component\OptionsResolver\OptionsResolver;
  19. class HtFileType extends AbstractType
  20. {
  21.     public function buildForm(FormBuilderInterface $builder, array $options): void
  22.     {
  23.         $builder
  24.             ->add('title'TextType::class, [
  25.                 'attr' => [
  26.                     'class' => 'form-control'
  27.                 ]
  28.             ])
  29.             ->add('status'ChoiceType::class, [
  30.                 // 'choices' mapea los valores a mostrar en el select con los valores reales
  31.                 'choices' => StatusHelper::STATUS_HT,
  32.                 'placeholder' => 'Selecciona un estado',
  33.                 'required' => true// O false, según sea necesario
  34.                 'attr' => [
  35.                     'class' => 'form-control'
  36.                 ]
  37.             ])
  38.             ->add('pax'NumberType::class, [
  39.                 'required' => false,
  40.                 'attr' => [
  41.                     'class' => 'form-control'
  42.                 ]
  43.             ])
  44.             ->add('description'TextareaType::class, [
  45.                 'required' => false,
  46.                 'attr' => [
  47.                     'class' => 'summernote'
  48.                 ]
  49.             ])
  50.             ->add('descriptionTwo'TextareaType::class, [
  51.                 'required' => false,
  52.                 'attr' => [
  53.                     'class' => 'summernote'
  54.                 ]
  55.             ])
  56.             ->add('clientContact'EntityType::class, [
  57.                 'class' => ClientContact::class,
  58.                 'expanded' => false,
  59.                 'multiple' => false,
  60.                 'choice_label' => 'name',
  61.                 'placeholder' => 'Selecciona un contacto',
  62.                 'required' => false,
  63.                 'attr' => [
  64.                     'disabled' => true
  65.                 ]
  66.             ])
  67.             ->add('contactUnregistered'TextType::class, [
  68.                 'required' => false,
  69.                 'attr' => [
  70.                     'class' => 'form-control'
  71.                 ]
  72.             ])
  73.             ->add('nameContactUnregistered'TextType::class, [
  74.                 'required' => false,
  75.                 'attr' => [
  76.                     'class' => 'form-control'
  77.                 ]
  78.             ])
  79.             ->add('phoneContactUnregistered'TelType::class, [
  80.                 'required' => false,
  81.                 'attr' => [
  82.                     'class' => 'form-control'
  83.                 ]
  84.             ])
  85.             ->add('dateStart'DateTimeType::class, [
  86.                 'html5' => true,
  87.                 // 'date_widget' y 'time_widget' permiten especificar cómo se deben renderizar los
  88.                 // selectores de fecha y hora cuando 'widget' => 'single_text' no es usado.
  89.                 // En este caso, se usarán los inputs HTML5 para fecha y hora respectivamente.
  90.                 'date_widget' => 'single_text',
  91.                 'time_widget' => 'single_text',
  92.                 // La opción 'required' es opcional dependiendo de si el campo es obligatorio o no
  93.                 'required' => false,
  94.             ])
  95.             ->add('dateEnd'DateTimeType::class, [
  96.                 'html5' => true,
  97.                 'date_widget' => 'single_text',
  98.                 'time_widget' => 'single_text',
  99.                 'required' => false,
  100.             ])
  101.             ->add('client'EntityType::class, [
  102.                 'class' => Client::class,
  103.                 'expanded' => false,
  104.                 'multiple' => false,
  105.                 'choice_label' => 'name',
  106.                 'placeholder' => 'Selecciona un cliente',
  107.                 'required' => false,
  108.             ])
  109.             
  110.         ;
  111.         if ($options['data']->getId() && !$options['data']->getHtItems()->isEmpty()) {
  112.             $builder->add('htItems'CollectionType::class, [
  113.                 'entry_type' => HtItemType::class,
  114.                 'entry_options' => ['label' => false],
  115.                 'allow_add' => true,
  116.                 'allow_delete' => true,
  117.                 'by_reference' => false,
  118.             ]);
  119.         }
  120.     }
  121.     public function configureOptions(OptionsResolver $resolver): void
  122.     {
  123.         $resolver->setDefaults([
  124.             'data_class' => HtFile::class,
  125.         ]);
  126.     }
  127. }