Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UserType | |
100.00% |
23 / 23 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| buildForm | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
1 | |||
| configureOptions | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Form; |
| 4 | |
| 5 | use App\Entity\User; |
| 6 | use Symfony\Component\Form\AbstractType; |
| 7 | use Symfony\Component\Form\FormBuilderInterface; |
| 8 | use Symfony\Component\OptionsResolver\OptionsResolver; |
| 9 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
| 10 | use Symfony\Component\Form\Extension\Core\Type\EmailType; |
| 11 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
| 12 | use Symfony\Component\Form\Extension\Core\Type\PasswordType; |
| 13 | use Symfony\Component\Form\Extension\Core\Type\RepeatedType; |
| 14 | |
| 15 | class UserType extends AbstractType |
| 16 | { |
| 17 | /** |
| 18 | * Build the form for creating or editing a user. |
| 19 | * |
| 20 | * @param FormBuilderInterface $builder The form builder |
| 21 | * @param array<mixed> $options The options for this form |
| 22 | * @return void |
| 23 | */ |
| 24 | public function buildForm(FormBuilderInterface $builder, array $options): void |
| 25 | { |
| 26 | $builder |
| 27 | ->add('username', TextType::class, ['label' => "Nom d'utilisateur"]) |
| 28 | ->add('password', RepeatedType::class, [ |
| 29 | 'type' => PasswordType::class, |
| 30 | 'invalid_message' => 'Les deux mots de passe doivent correspondre.', |
| 31 | 'required' => true, |
| 32 | 'first_options' => ['label' => 'Mot de passe'], |
| 33 | 'second_options' => ['label' => 'Ressaisir le mot de passe'], |
| 34 | ]) |
| 35 | ->add('email', EmailType::class, ['label' => 'Adresse email']) |
| 36 | ->add('roles', ChoiceType::class, [ |
| 37 | 'choices' => [ |
| 38 | 'Administrateur' => 'ROLE_ADMIN', |
| 39 | 'Utilisateur' => 'ROLE_USER', |
| 40 | ], |
| 41 | 'multiple' => true, |
| 42 | 'expanded' => true, |
| 43 | 'label' => 'Rôles', |
| 44 | 'required' => true, |
| 45 | ]); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Configure the options for the User form. |
| 50 | * |
| 51 | * @param OptionsResolver $resolver The options resolver. |
| 52 | * @return void |
| 53 | */ |
| 54 | public function configureOptions(OptionsResolver $resolver): void |
| 55 | { |
| 56 | $resolver->setDefaults([ |
| 57 | 'data_class' => User::class, |
| 58 | ]); |
| 59 | } |
| 60 | } |