src/Form/Ecommerce/AddressBillableType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form\Ecommerce;
  3. use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CountryType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\Intl\NumberFormatter\NumberFormatter;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\Regex;
  11. use Symfony\Component\Validator\Constraints\Type;
  12. /**
  13.  * @author David Velasco <dvelasco@wearemarketing.com>
  14.  */
  15. class AddressBillableType extends AbstractType
  16. {
  17.     /**
  18.      * @var string
  19.      */
  20.     private $class;
  21.     /**
  22.      * @param string $class
  23.      */
  24.     public function __construct($class)
  25.     {
  26.         $this->class $class;
  27.     }
  28.     /**
  29.      * {@inheritdoc}
  30.      */
  31.     public function buildForm(FormBuilderInterface $builder, array $options)
  32.     {
  33.         $builder
  34.             ->add('name'null, ['label' => 'ecommerce.label.address.name'])
  35.             ->add('surname'null, ['label' => 'ecommerce.label.address.name'])
  36.             ->add('nif'null, ['label' => 'ecommerce.label.address.nif'])
  37.             ->add('addressLine1'null, ['label' => 'ecommerce.label.address.address_line_1'])
  38.             ->add('addressLine2'null, ['label' => 'ecommerce.label.address.address_line_2'])
  39.             ->add(
  40.                 'city',
  41.                 null,
  42.                 [
  43.                     'label' => 'ecommerce.label.address.city',
  44.                 ]
  45.             )
  46.             ->add('province'null, [
  47.                 'label' => 'ecommerce.label.address.province',
  48.             ])
  49.             ->add('postalCode'TextType::class, [
  50.                 'label' => 'ecommerce.label.address.postalCode',
  51.                 'constraints' => [
  52.                     new Regex(['pattern' => '/\d/''groups' => ['Checkout'], 'message' => 'postal_code.type'])
  53.                 ],
  54.                 'attr' => [
  55.                     'pattern' => '\d*',
  56.                     'inputmode' => "numeric",
  57.                     "min"  => 0.1
  58.                 ],
  59.             ])
  60.             ->add('email'null, [
  61.                 'label' => 'ecommerce.label.address.email',
  62.             ])
  63.             ->add('country'CountryType::class, [
  64.                 'label' => 'ecommerce.label.address.country',
  65.                 'preferred_choices' => ['ES'],
  66.             ])
  67.             ->add('phone'PhoneNumberType::class, ['widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE'preferred_country_choices' => ['ES']])
  68.             ->add('acceptOfferAndNew'null, ['label' => 'form.offer']);
  69.     }
  70.     public function configureOptions(OptionsResolver $resolver)
  71.     {
  72.         $resolver->setDefaults([
  73.             'data_class' => $this->class,
  74.             'validation_groups' => 'Checkout',
  75.             'csrf_protection' => false,
  76.             'allow_extra_fields' => true,
  77.         ]);
  78.     }
  79.     /**
  80.      * {@inheritdoc}
  81.      */
  82.     public function getName()
  83.     {
  84.         return 'wam_ecommerce_addressbillable';
  85.     }
  86. }