Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 66 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
DomainType | |
0.00% |
0 / 66 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
buildForm | |
0.00% |
0 / 59 |
|
0.00% |
0 / 1 |
12 | |||
configureOptions | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of the MADIS - RGPD Management application. |
5 | * |
6 | * @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU Affero General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU Affero General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Affero General Public License |
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | declare(strict_types=1); |
23 | |
24 | namespace App\Domain\Maturity\Form\Type; |
25 | |
26 | use App\Domain\Maturity\Model\Domain; |
27 | use Symfony\Component\Form\AbstractType; |
28 | use Symfony\Component\Form\Extension\Core\Type\ButtonType; |
29 | use Symfony\Component\Form\Extension\Core\Type\CollectionType; |
30 | use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
31 | use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
32 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
33 | use Symfony\Component\Form\FormBuilderInterface; |
34 | use Symfony\Component\Form\FormEvent; |
35 | use Symfony\Component\Form\FormEvents; |
36 | use Symfony\Component\OptionsResolver\OptionsResolver; |
37 | |
38 | class DomainType extends AbstractType |
39 | { |
40 | /** |
41 | * Build type form. |
42 | */ |
43 | public function buildForm(FormBuilderInterface $builder, array $options) |
44 | { |
45 | $builder |
46 | ->add('name', TextType::class, [ |
47 | 'label' => 'maturity.referentiel.label.section', |
48 | 'required' => true, |
49 | 'attr' => [ |
50 | 'maxlength' => 1000, |
51 | ], |
52 | 'purify_html' => true, |
53 | ]) |
54 | |
55 | ->add('description', TextareaType::class, [ |
56 | 'label' => 'maturity.referentiel.label.description', |
57 | 'required' => false, |
58 | 'attr' => [ |
59 | 'rows' => 3, |
60 | ], |
61 | 'purify_html' => true, |
62 | ]) |
63 | |
64 | ->add('questions', CollectionType::class, [ |
65 | 'entry_type' => QuestionType::class, |
66 | 'allow_add' => true, |
67 | 'allow_delete' => true, |
68 | 'by_reference' => false, |
69 | 'prototype_name' => '__question_name__', |
70 | ]) |
71 | |
72 | ->add('position', HiddenType::class, [ |
73 | 'required' => true, |
74 | 'attr' => [ |
75 | 'class' => 'domain-position', |
76 | ], |
77 | ]) |
78 | ->add('color', HiddenType::class, [ |
79 | 'required' => false, |
80 | 'attr' => [ |
81 | 'class' => 'domain-color', |
82 | ], |
83 | ]); |
84 | |
85 | $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { |
86 | $form = $event->getForm(); |
87 | if (null !== $data = $event->getData()) { |
88 | $form->add('addQuestion', ButtonType::class, [ |
89 | 'label' => 'maturity.referentiel.action.add_question', |
90 | 'label_html' => true, |
91 | 'attr' => [ |
92 | 'class' => 'add_question btn btn-primary', |
93 | 'data-section' => ($data ? $data->getId() : ''), |
94 | 'data-collection-holder-class' => 'referentielQuestions', |
95 | ], |
96 | ]); |
97 | } else { |
98 | $form->add('addQuestion', ButtonType::class, [ |
99 | 'label' => 'maturity.referentiel.action.add_question', |
100 | 'label_html' => true, |
101 | 'attr' => [ |
102 | 'class' => 'add_question btn btn-primary', |
103 | 'data-section' => '__section_name__', |
104 | 'data-collection-holder-class' => 'referentielQuestions', |
105 | ], |
106 | ]); |
107 | } |
108 | }) |
109 | ; |
110 | } |
111 | |
112 | /** |
113 | * Provide type options. |
114 | */ |
115 | public function configureOptions(OptionsResolver $resolver) |
116 | { |
117 | $resolver |
118 | ->setDefaults([ |
119 | 'data_class' => Domain::class, |
120 | 'validation_groups' => [ |
121 | 'default', |
122 | ], |
123 | ]); |
124 | } |
125 | } |