SearchResultFeedbackForm::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Yves\FactFinder\Form;
9
10
use Spryker\Yves\Kernel\Form\AbstractType;
11
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
12
use Symfony\Component\Form\Extension\Core\Type\TextType;
13
use Symfony\Component\Form\FormBuilderInterface;
14
use Symfony\Component\OptionsResolver\OptionsResolver;
15
use Symfony\Component\Validator\Constraints\NotBlank;
16
17
class SearchResultFeedbackForm extends AbstractType
18
{
19
    const FIELD_POSITIVE = 'positive';
20
    const FIELD_MESSAGE = 'message';
21
    const FORM_ID = 'searchResultFeedback';
22
23
    /**
24
     * @return string
25
     */
26
    public function getName()
27
    {
28
        return 'searchResultFeedbackForm';
29
    }
30
31
    /**
32
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
33
     *
34
     * @return void
35
     */
36
    public function configureOptions(OptionsResolver $resolver)
37
    {
38
        $resolver->setDefaults([
39
            'attr' => [
40
                'id' => self::FORM_ID,
41
            ],
42
        ]);
43
    }
44
45
    /**
46
     * @deprecated Use `configureOptions()` instead.
47
     *
48
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
49
     *
50
     * @return void
51
     */
52
    public function setDefaultOptions(OptionsResolver $resolver)
53
    {
54
        $this->configureOptions($resolver);
55
    }
56
57
    /**
58
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
59
     * @param array $options
60
     *
61
     * @return void
62
     */
63
    public function buildForm(FormBuilderInterface $builder, array $options)
64
    {
65
        $builder
66
            ->setAction('#');
67
68
        $this
69
            ->addPositiveField($builder)
70
            ->addMessageField($builder);
71
    }
72
73
    /**
74
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
75
     *
76
     * @return $this
77
     */
78
    protected function addPositiveField(FormBuilderInterface $builder)
79
    {
80
        $builder->add(self::FIELD_POSITIVE, ChoiceType::class, [
81
            'choices' => [
82
                'true' => 'factfinder.feedback.positive.value.positive',
83
                'false' => 'factfinder.feedback.positive.value.negative',
84
            ],
85
            'required' => true,
86
            'label' => 'factfinder.feedback.positive',
87
            'constraints' => [
88
                new NotBlank(),
89
            ],
90
        ]);
91
92
        return $this;
93
    }
94
95
    /**
96
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
97
     *
98
     * @return $this
99
     */
100
    protected function addMessageField(FormBuilderInterface $builder)
101
    {
102
        $builder->add(self::FIELD_MESSAGE, TextType::class, [
103
            'label' => 'factfinder.feedback.message',
104
            'required' => false,
105
        ]);
106
107
        return $this;
108
    }
109
}
110