forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrderItemType.php
57 lines (50 loc) · 1.53 KB
/
OrderItemType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Form\Type;
use Sylius\Bundle\OrderBundle\Form\Type\OrderItemType as BaseOrderItemType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* Order item type.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class OrderItemType extends BaseOrderItemType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {
$data = $event->getData();
if (isset($data['variant'])) {
$event->getForm()->add('variant', 'entity_hidden', array(
'data_class' => $options['variant_data_class'],
));
}
})
;
}
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
parent::setDefaultOptions($resolver);
$resolver->setDefaults(array(
'variant_data_class' => 'Sylius\Component\Core\Model\ProductVariant',
));
}
}