Completed
Push — master ( 33f9ae...230277 )
by Paweł
13:09 queued 15s
created

CustomerType::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
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\UserBundle\Form\Type;
13
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
use Symfony\Component\Form\FormBuilderInterface;
16
use Symfony\Component\OptionsResolver\OptionsResolver;
17
18
/**
19
 * @author Michał Marcinkowski <[email protected]>
20
 */
21
class CustomerType extends CustomerProfileType
22
{
23
    /**
24
     * @var EventSubscriberInterface
25
     */
26
    private $addUserFormSubscriber;
27
28
    /**
29
     * @param string $dataClass
30
     * @param string[] $validationGroups
31
     * @param EventSubscriberInterface $addUserFormSubscriber
32
     */
33
    public function __construct($dataClass, array $validationGroups = [], EventSubscriberInterface $addUserFormSubscriber)
34
    {
35
        parent::__construct($dataClass, $validationGroups);
36
        $this->addUserFormSubscriber = $addUserFormSubscriber;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function buildForm(FormBuilderInterface $builder, array $options)
43
    {
44
        parent::buildForm($builder, $options);
45
        $builder
46
            ->add('groups', 'sylius_group_choice', [
47
                'label' => 'sylius.form.customer.groups',
48
                'multiple' => true,
49
                'required' => false,
50
            ])
51
            ->addEventSubscriber($this->addUserFormSubscriber)
52
        ;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function configureOptions(OptionsResolver $resolver)
59
    {
60
        $resolver->setDefaults([
61
            'data_class' => $this->dataClass,
62
            'validation_groups' => $this->validationGroups,
63
            'cascade_validation' => true,
64
        ]);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getName()
71
    {
72
        return 'sylius_customer';
73
    }
74
}
75