<?php
namespace App\Form;
use App\Entity\Client;
use App\Entity\ClientContact;
use App\Entity\HtFile;
use App\Entity\Supplier;
use App\Helper\StatusHelper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class HtFileType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title', TextType::class, [
'attr' => [
'class' => 'form-control'
]
])
->add('status', ChoiceType::class, [
// 'choices' mapea los valores a mostrar en el select con los valores reales
'choices' => StatusHelper::STATUS_HT,
'placeholder' => 'Selecciona un estado',
'required' => true, // O false, según sea necesario
'attr' => [
'class' => 'form-control'
]
])
->add('pax', NumberType::class, [
'required' => false,
'attr' => [
'class' => 'form-control'
]
])
->add('description', TextareaType::class, [
'required' => false,
'attr' => [
'class' => 'summernote'
]
])
->add('descriptionTwo', TextareaType::class, [
'required' => false,
'attr' => [
'class' => 'summernote'
]
])
->add('clientContact', EntityType::class, [
'class' => ClientContact::class,
'expanded' => false,
'multiple' => false,
'choice_label' => 'name',
'placeholder' => 'Selecciona un contacto',
'required' => false,
'attr' => [
'disabled' => true
]
])
->add('contactUnregistered', TextType::class, [
'required' => false,
'attr' => [
'class' => 'form-control'
]
])
->add('nameContactUnregistered', TextType::class, [
'required' => false,
'attr' => [
'class' => 'form-control'
]
])
->add('phoneContactUnregistered', TelType::class, [
'required' => false,
'attr' => [
'class' => 'form-control'
]
])
->add('dateStart', DateTimeType::class, [
'html5' => true,
// 'date_widget' y 'time_widget' permiten especificar cómo se deben renderizar los
// selectores de fecha y hora cuando 'widget' => 'single_text' no es usado.
// En este caso, se usarán los inputs HTML5 para fecha y hora respectivamente.
'date_widget' => 'single_text',
'time_widget' => 'single_text',
// La opción 'required' es opcional dependiendo de si el campo es obligatorio o no
'required' => false,
])
->add('dateEnd', DateTimeType::class, [
'html5' => true,
'date_widget' => 'single_text',
'time_widget' => 'single_text',
'required' => false,
])
->add('client', EntityType::class, [
'class' => Client::class,
'expanded' => false,
'multiple' => false,
'choice_label' => 'name',
'placeholder' => 'Selecciona un cliente',
'required' => false,
])
;
if ($options['data']->getId() && !$options['data']->getHtItems()->isEmpty()) {
$builder->add('htItems', CollectionType::class, [
'entry_type' => HtItemType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
]);
}
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => HtFile::class,
]);
}
}