<?php
namespace App\Form\Ecommerce;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Intl\NumberFormatter\NumberFormatter;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Validator\Constraints\Type;
/**
* @author David Velasco <dvelasco@wearemarketing.com>
*/
class AddressBillableType extends AbstractType
{
/**
* @var string
*/
private $class;
/**
* @param string $class
*/
public function __construct($class)
{
$this->class = $class;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', null, ['label' => 'ecommerce.label.address.name'])
->add('surname', null, ['label' => 'ecommerce.label.address.name'])
->add('nif', null, ['label' => 'ecommerce.label.address.nif'])
->add('addressLine1', null, ['label' => 'ecommerce.label.address.address_line_1'])
->add('addressLine2', null, ['label' => 'ecommerce.label.address.address_line_2'])
->add(
'city',
null,
[
'label' => 'ecommerce.label.address.city',
]
)
->add('province', null, [
'label' => 'ecommerce.label.address.province',
])
->add('postalCode', TextType::class, [
'label' => 'ecommerce.label.address.postalCode',
'constraints' => [
new Regex(['pattern' => '/\d/', 'groups' => ['Checkout'], 'message' => 'postal_code.type'])
],
'attr' => [
'pattern' => '\d*',
'inputmode' => "numeric",
"min" => 0.1
],
])
->add('email', null, [
'label' => 'ecommerce.label.address.email',
])
->add('country', CountryType::class, [
'label' => 'ecommerce.label.address.country',
'preferred_choices' => ['ES'],
])
->add('phone', PhoneNumberType::class, ['widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE, 'preferred_country_choices' => ['ES']])
->add('acceptOfferAndNew', null, ['label' => 'form.offer']);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => $this->class,
'validation_groups' => 'Checkout',
'csrf_protection' => false,
'allow_extra_fields' => true,
]);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'wam_ecommerce_addressbillable';
}
}