TeamType::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Xdaysaysay\AdminBundle\Form\Type;
4
5
use Symfony\Component\Form\AbstractType;
6
use Symfony\Component\Form\FormBuilderInterface;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
use Symfony\Component\Validator\Constraints as Assert;
9
use Vich\UploaderBundle\Form\Type\VichImageType;
10
use Xdaysaysay\CoreBundle\Form\Type\XdaysaysayTextType;
11
12
/**
13
 * Class TeamType
14
 * @package Xdaysaysay\AdminBundle\Form\Type
15
 */
16
class TeamType extends AbstractType
17
{
18
    /**
19
     * @param FormBuilderInterface $builder
20
     * @param array $options
21
     *
22
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
23
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
24
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
25
     */
26
    public function buildForm(FormBuilderInterface $builder, array $options)
27
    {
28
        $builder->add('name', null, [
29
            'label'       => 'admin.team.form.label.name',
30
            'constraints' => [
31
                new Assert\NotBlank(),
32
            ],
33
        ]);
34
        $builder->add('logoFile', VichImageType::class, array(
35
            'required' => false,
36
        ));
37
        $builder->add('ircServer', null, [
38
            'label' => 'admin.team.form.label.ircServer',
39
        ]);
40
        $builder->add('chan_name', null, [
41
            'label'       => 'admin.team.form.label.chan_name',
42
            'constraints' => [
43
                new Assert\NotBlank(),
44
                new Assert\Regex([
45
                    'pattern' => '/^#(.*)/',
46
                    'message' => 'must_start_with_hashtag'
47
                ]),
48
            ],
49
        ]);
50
        $builder->add('chan_name_password', null, [
51
            'label' => 'admin.team.form.label.chan_name_password',
52
            'required' => false,
53
        ]);
54
        $builder->add('chan_name_staff', null, [
55
            'label' => 'admin.team.form.label.chan_name_staff',
56
            'required' => false,
57
            'constraints' => [
58
                new Assert\Regex([
59
                    'pattern' => '/^#(.*)/',
60
                    'message' => 'must_start_with_hashtag'
61
                ]),
62
            ],
63
        ]);
64
        $builder->add('chan_name_staff_password', null, [
65
            'label' => 'admin.team.form.label.chan_name_staff_password',
66
            'required' => false,
67
        ]);
68
        $builder->add('bot_name', null, [
69
            'label' => 'admin.team.form.label.bot_name',
70
            'required' => false,
71
            'label_attr' => [
72
                'help' => 'admin.team.form.label.bot_name_help'
73
            ],
74
        ]);
75
    }
76
77
    /**
78
     * @param OptionsResolver $resolver
79
     *
80
     * @throws \Symfony\Component\OptionsResolver\Exception\AccessException
81
     */
82
    public function configureOptions(OptionsResolver $resolver)
83
    {
84
        $resolver->setDefaults([
85
            'data_class'         => 'Xdaysaysay\CoreBundle\Entity\Team',
86
            'translation_domain' => 'admin',
87
        ]);
88
    }
89
}
90