src/Form/Ecommerce/AddressShippableType.php line 20

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\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\CountryType;
  7. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  8. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\Form\FormInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. /**
  15.  * Class AddressShippableType.
  16.  */
  17. class AddressShippableType extends AbstractType
  18. {
  19.     private $class;
  20.     /**
  21.      * @param string $class
  22.      */
  23.     public function __construct($class)
  24.     {
  25.         $this->class $class;
  26.     }
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public function buildForm(FormBuilderInterface $builder, array $options)
  31.     {
  32.         if ($options['same_as_billing']) {
  33.             $builder
  34.                 ->add('sameAsBilling'CheckboxType::class, [
  35.                     'required' => false,
  36.                     'mapped' => false,
  37.                     'label' => 'ecommerce.label.address.same_as_billing',
  38.                 ])
  39.             ;
  40.         }
  41.         $builder
  42.             ->add('name'null, ['label' => 'form.global.label_name''required' => true])
  43.             ->add('surname'null, ['label' => 'form.global.label_surname''required' => true])
  44.             ->add('nif'HiddenType::class, ['label' => 'form.global.label_nif''data' => 'ssss''empty_data' => 'ssss'])
  45.             ->add('email'EmailType::class, ['label' => 'form.global.label_email''required' => true])
  46.             ->add('phone'PhoneNumberType::class, ['widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE'preferred_country_choices' => ['ES'], 'required' => true])
  47.             ->add('addressLine1'null, ['label' => 'form.global.label_address''required' => true])
  48.             ->add(
  49.                 'city',
  50.                 null,
  51.                 [
  52.                     'label' => 'ecommerce.label.address.city',
  53.                     'required' => true,
  54.                 ]
  55.             )
  56.             ->add('postalCode'TextType::class, [
  57.                 'label' => 'ecommerce.label.address.postalCode',
  58.                 'required' => true,
  59.             ])
  60.             ->add('country'CountryType::class, [
  61.                 'label' => 'ecommerce.label.address.country',
  62.                 'preferred_choices' => ['ES'],
  63.                 'required' => true,
  64.             ])
  65.             ->add('comment'TextareaType::class, [
  66.                 'label' => 'form.global.label_comment',
  67.             ])
  68.         ;
  69.     }
  70.     public function configureOptions(OptionsResolver $resolver)
  71.     {
  72.         $resolver->setDefaults([
  73.             'data_class' => $this->class,
  74.             'validation_groups' => function (FormInterface $form) {
  75.                 if ($form->has('sameAsBilling') && $form->get('sameAsBilling')->getData()) {
  76.                     return [];
  77.                 }
  78.                 return ['Checkout'];
  79.             },
  80.             'csrf_protection' => false,
  81.             'allow_extra_fields' => true,
  82.             'same_as_billing' => false,
  83.         ]);
  84.     }
  85.     /**
  86.      * {@inheritdoc}
  87.      */
  88.     public function getName()
  89.     {
  90.         return 'wam_ecommerce_addressshippable';
  91.     }
  92. }