|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Yves\Braintree\Form; |
|
9
|
|
|
|
|
10
|
|
|
use Spryker\Yves\Kernel\Form\AbstractType; |
|
11
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
12
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
13
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
14
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @method \SprykerEco\Yves\Braintree\BraintreeConfig getConfig() |
|
18
|
|
|
*/ |
|
19
|
|
|
class CheckoutShipmentForm extends AbstractType |
|
20
|
|
|
{ |
|
21
|
|
|
public const FIELD_ID_SHIPMENT_METHOD = 'idShipmentMethod'; |
|
22
|
|
|
|
|
23
|
|
|
public const OPTION_SHIPMENT_METHODS = 'shipmentMethods'; |
|
24
|
|
|
public const OPTION_ID_SELECTED_SHIPMENT_METHOD = 'idSelectedShipmentMethod'; |
|
25
|
|
|
|
|
26
|
|
|
public const SHIPMENT_PROPERTY_PATH = 'shipment'; |
|
27
|
|
|
public const SHIPMENT_SELECTION = 'shipmentSelection'; |
|
28
|
|
|
public const SHIPMENT_SELECTION_PROPERTY_PATH = self::SHIPMENT_PROPERTY_PATH . '.' . self::SHIPMENT_SELECTION; |
|
29
|
|
|
|
|
30
|
|
|
public const FORM_NAME = 'checkoutShipmentForm'; |
|
31
|
|
|
|
|
32
|
|
|
protected const VALIDATION_NOT_BLANK_MESSAGE = 'validation.not_blank'; |
|
33
|
|
|
protected const ACTION_URL = '/paypal-express/shipment/add'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getBlockPrefix(): string |
|
39
|
|
|
{ |
|
40
|
|
|
return static::FORM_NAME; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
45
|
|
|
* @param array $options |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
50
|
|
|
{ |
|
51
|
|
|
$builder->setAction(static::ACTION_URL); |
|
52
|
|
|
|
|
53
|
|
|
$this->addIdShipmentMethod($builder, $options); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
58
|
|
|
* @param array $options |
|
59
|
|
|
* |
|
60
|
|
|
* @return void |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function addIdShipmentMethod(FormBuilderInterface $builder, array $options): void |
|
63
|
|
|
{ |
|
64
|
|
|
$builder->add(static::FIELD_ID_SHIPMENT_METHOD, ChoiceType::class, [ |
|
65
|
|
|
'choices' => $options[static::OPTION_SHIPMENT_METHODS], |
|
66
|
|
|
'expanded' => true, |
|
67
|
|
|
'multiple' => false, |
|
68
|
|
|
'required' => true, |
|
69
|
|
|
'property_path' => static::SHIPMENT_SELECTION_PROPERTY_PATH, |
|
70
|
|
|
'placeholder' => false, |
|
71
|
|
|
'constraints' => [ |
|
72
|
|
|
new NotBlank(), |
|
73
|
|
|
], |
|
74
|
|
|
'label' => false, |
|
75
|
|
|
'data' => $options[static::OPTION_ID_SELECTED_SHIPMENT_METHOD], |
|
76
|
|
|
]); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public function configureOptions(OptionsResolver $resolver): void |
|
85
|
|
|
{ |
|
86
|
|
|
$resolver->setRequired(static::OPTION_SHIPMENT_METHODS); |
|
87
|
|
|
$resolver->setRequired(static::OPTION_ID_SELECTED_SHIPMENT_METHOD); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|