Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.41% |
66 / 73 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ContactType | |
90.41% |
66 / 73 |
|
66.67% |
2 / 3 |
10.09 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
buildForm | |
89.39% |
59 / 66 |
|
0.00% |
0 / 1 |
8.08 | |||
configureOptions | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
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\User\Form\Type; |
25 | |
26 | use App\Domain\User\Model\Embeddable\Contact; |
27 | use Knp\DictionaryBundle\Form\Type\DictionaryType; |
28 | use Symfony\Component\Form\AbstractType; |
29 | use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
30 | use Symfony\Component\Form\Extension\Core\Type\EmailType; |
31 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
32 | use Symfony\Component\Form\FormBuilderInterface; |
33 | use Symfony\Component\HttpFoundation\RequestStack; |
34 | use Symfony\Component\OptionsResolver\OptionsResolver; |
35 | |
36 | class ContactType extends AbstractType |
37 | { |
38 | private RequestStack $requestStack; |
39 | private bool $activeNotifications; |
40 | |
41 | public function __construct(RequestStack $requestStack, bool $activeNotifications) |
42 | { |
43 | $this->requestStack = $requestStack; |
44 | $this->activeNotifications = $activeNotifications; |
45 | } |
46 | |
47 | /** |
48 | * Build type form. |
49 | */ |
50 | public function buildForm(FormBuilderInterface $builder, array $options) |
51 | { |
52 | $request = $this->requestStack->getCurrentRequest(); |
53 | |
54 | $intersectIsEmpty = empty(\array_intersect( |
55 | [ |
56 | 'collectivity_legal_manager', |
57 | 'collectivity_referent', |
58 | 'collectivity_comite_il_contact', |
59 | ], |
60 | $options['validation_groups'] ?? [] |
61 | )); |
62 | |
63 | $required = $intersectIsEmpty ? false : true; |
64 | |
65 | $isComiteIl = in_array('collectivity_comite_il_contact', $options['validation_groups'] ?? []); |
66 | |
67 | $builder |
68 | ->add('civility', DictionaryType::class, [ |
69 | 'label' => 'global.label.contact.civility', |
70 | 'required' => $required, |
71 | 'name' => 'user_contact_civility', |
72 | ]) |
73 | ->add('firstName', TextType::class, [ |
74 | 'label' => 'global.label.contact.first_name', |
75 | 'required' => $required, |
76 | 'attr' => [ |
77 | 'maxlength' => 255, |
78 | ], |
79 | 'purify_html' => true, |
80 | ]) |
81 | ->add('lastName', TextType::class, [ |
82 | 'label' => 'global.label.contact.last_name', |
83 | 'required' => $required, |
84 | 'attr' => [ |
85 | 'maxlength' => 255, |
86 | ], |
87 | 'purify_html' => true, |
88 | ]) |
89 | ->add('job', TextType::class, [ |
90 | 'label' => 'global.label.contact.job', |
91 | 'required' => $required, |
92 | 'attr' => [ |
93 | 'maxlength' => 255, |
94 | ], |
95 | 'purify_html' => true, |
96 | ]) |
97 | ->add('mail', EmailType::class, [ |
98 | 'label' => 'global.label.contact.email', |
99 | 'required' => $isComiteIl ? false : $required, |
100 | 'attr' => [ |
101 | 'maxlength' => 255, |
102 | ], |
103 | 'purify_html' => true, |
104 | ]) |
105 | ; |
106 | |
107 | // Email notification only available on collectivity page for responsable traitement and referent RGPD |
108 | if ($this->activeNotifications |
109 | && ( |
110 | in_array('collectivity_legal_manager', $options['validation_groups'] ?? []) |
111 | || in_array('collectivity_referent', $options['validation_groups'] ?? []) |
112 | || in_array('collectivity_dpo', $options['validation_groups'] ?? []) |
113 | ) |
114 | ) { |
115 | $builder->add('notification', CheckboxType::class, [ |
116 | 'label' => 'notifications.label.activate_notification_email', |
117 | 'required' => false, |
118 | ]); |
119 | } |
120 | |
121 | $builder->add('phoneNumber', TextType::class, [ |
122 | 'label' => 'global.label.contact.phone_number', |
123 | 'required' => $isComiteIl ? false : $required, |
124 | 'attr' => [ |
125 | 'maxlength' => 10, |
126 | ], |
127 | 'purify_html' => true, |
128 | ]); |
129 | } |
130 | |
131 | /** |
132 | * Provide type options. |
133 | */ |
134 | public function configureOptions(OptionsResolver $resolver) |
135 | { |
136 | $resolver |
137 | ->setDefaults([ |
138 | 'data_class' => Contact::class, |
139 | 'validation_groups' => 'default', |
140 | ]); |
141 | } |
142 | } |