src/Form/CustomerServiceType.php line 20
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
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;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Contracts\Translation\TranslatorInterface;
class CustomerServiceType extends AbstractType
{
private $transalor;
public function __construct(TranslatorInterface $translator)
{
$this->transalor = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class)
->add('surname', TextType::class)
->add('email', EmailType::class)
->add('phone', TelType::class)
->add('reason', ChoiceType::class,[
'required' => true,
'choices' => [
$this->transalor->trans('form.labels.customer_service.reason') => null,
$this->transalor->trans('form.choices.customer_service.product_reports') => 1,
$this->transalor->trans('form.choices.customer_service.product_informations') => 2,
$this->transalor->trans('form.choices.customer_service.product_location') => 3,
$this->transalor->trans('form.common_values.other') => 4,
],
'constraints' => [
new Assert\NotNull([
])
]
])
->add('productName', TextType::class, [
'attr' => [
'class' => 'product-report'
]
])
->add('productionLot', TextType::class)
->add('expirationDate', DateType::class,[
'widget' => 'single_text',
])
->add('productRetirament', ChoiceType::class,[
'required' => true,
'choices' => [
$this->transalor->trans('form.common_values.no') => 'no',
$this->transalor->trans('form.common_values.yes') => 'yes',
]
])
->add('file', FileType::class, [
'required' => true,
'constraints' => [
new Assert\File([
'maxSize' => '8M',
'mimeTypes' => [
'image/jpeg',
'image/jpg',
'image/png',
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => $this->transalor->trans('form.errors.wrong_file_type'),
])
],
])
->add('city', TextType::class)
->add('message', TextareaType::class)
->add('privacy', CheckboxType::class)
->add('data', ChoiceType::class, [
'choices' => [
$this->transalor->trans('form.choices.privacy.not_agree') => 0,
$this->transalor->trans('form.choices.privacy.agree') => 1
],
'required' => true,
'expanded' => true
])
// ->add('data2', ChoiceType::class, [
// 'choices' => [
// $this->transalor->trans('form.choices.privacy.not_agree') => 0,
// $this->transalor->trans('form.choices.privacy.agree') => 1
// ],
// 'required' => true,
// 'expanded' => true
// ])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
// 'mapped' => false,
]);
}
}