Completed
Push — master ( 5e83e1...bc9f64 )
by Paweł
50:52 queued 36:16
created

ApiProductTypeExtension::getExtendedType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ApiBundle\Form\Extension;
13
14
use Sylius\Bundle\ApiBundle\Form\EventSubscriber\RemoveVariantSelectionFieldFormSubscriber;
15
use Sylius\Bundle\ProductBundle\Form\Type\ProductType;
16
use Symfony\Component\Form\AbstractTypeExtension;
17
use Symfony\Component\Form\FormBuilderInterface;
18
use Symfony\Component\Form\FormEvent;
19
use Symfony\Component\Form\FormEvents;
20
21
/**
22
 * @author Anna Walasek <[email protected]>
23
 */
24
final class ApiProductTypeExtension extends AbstractTypeExtension
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function buildForm(FormBuilderInterface $builder, array $options)
30
    {
31
        $builder->addEventListener(FormEvents::PRE_SUBMIT , function (FormEvent $event) {
32
            $data = $event->getData();
33
34
            if (!array_key_exists('variantSelectionMethod', $data)) {
35
                $form = $event->getForm();
36
                $form->remove('variantSelectionMethod');
37
            }
38
        });
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getExtendedType()
45
    {
46
        return ProductType::class;
47
    }
48
}
49