Test Failed
Push — develop ( f1bc6f...c58911 )
by Stone
04:52
created

TrickTypeForm::configureOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Form;
4
5
use App\Entity\Category;
6
use App\Entity\Trick;
7
use App\Form\Type\TagsType;
8
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
9
use Symfony\Component\Form\AbstractType;
10
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
11
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
12
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
13
use Symfony\Component\Form\Extension\Core\Type\TextType;
14
use Symfony\Component\Form\FormBuilderInterface;
15
use Symfony\Component\OptionsResolver\OptionsResolver;
16
17
class TrickTypeForm extends AbstractType
18
{
19
20
    public function buildForm(FormBuilderInterface $builder, array $options)
21
    {
22
23
        if($options['all_tags_json'] === '' || $options['trick_tags_json'] === ''){
24
            throw new \UnexpectedValueException("all_tags_json or trick_tags_json not defined in the form constructor");
25
        }
26
27
        $builder
28
            ->add('name', TextType::class, [
29
                'label' => 'Name of the trick, must be at least 5 characters'
30
            ])
31
            ->add('text', TextareaType::class, [
32
                'label' => 'Describe the trick',
33
                'attr' => [
34
                    'class' => 'materialize-textarea'
35
                ]
36
            ])
37
            ->add('category', EntityType::class, [
38
                'class' => Category::class,
39
                'choice_label' => 'Name',
40
            ])
41
            ->add('tags', TagsType::class)
42
            ->add('save', SubmitType::class, [
43
                'label' => $options['save_button_label'],
44
                'attr' => [
45
                    'class' => 'waves-effect waves-light btn right mr-2'
46
                ]
47
            ])
48
            ->add('tagsData', HiddenType::class, [
49
                "mapped" => false,
50
                'attr' => [
51
                    'class' => 'trick-tag-data',
52
                    'data-all-tags-json' => $options['all_tags_json'],
53
                    'data-trick-tags-json' => $options['trick_tags_json'],
54
                ]
55
56
            ])
57
        ;
58
    }
59
60
    public function configureOptions(OptionsResolver $resolver)
61
    {
62
        $resolver->setDefaults([
63
            'data_class' => Trick::class,
64
            'save_button_label' => 'Save',
65
            'all_tags_json' => '',
66
            'trick_tags_json' => '',
67
        ]);
68
    }
69
}
70