<?php
namespace App\Form\Ecommerce;
use App\Entity\ShippingData;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
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\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* Class SendingEmailType.
*/
class SendingEmailType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, array(
'label' => 'form.global.label_name',
'required' => true,
'constraints' => [new NotBlank(['groups' => ['Email']])]
))
->add('surname', TextType::class, array(
'label' => 'form.global.label_surname',
'required' => false,
'constraints' => [new NotBlank(['groups' => ['Email']])]
))
->add('email', EmailType::class, array(
'label' => 'form.global.label_email',
'required' => true,
'constraints' => [new Email(['groups' => ['Email']]), new NotBlank(['groups' => ['Email']])]
))
->add('phone', PhoneNumberType::class, array(
'label' => 'form.global.label_phone',
'required' => true,
'widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE,
'preferred_country_choices' => array('ES'),
'constraints' => [new NotBlank(['groups' => ['Email']])]
))
->add('comment', TextareaType::class, array(
'label' => 'form.global.label_comment',
'required' => false,
));
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => ShippingData::class,
));
}
/**
* @return string
*/
public function getName()
{
return 'app_sending_email_type';
}
}