Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| RegistrationFormType | |
0.00% |
0 / 24 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| buildForm | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
2 | |||
| configureOptions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Form; |
| 4 | |
| 5 | use App\Entity\User; |
| 6 | use Symfony\Component\Form\AbstractType; |
| 7 | use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
| 8 | use Symfony\Component\Form\Extension\Core\Type\EmailType; |
| 9 | use Symfony\Component\Form\Extension\Core\Type\PasswordType; |
| 10 | use Symfony\Component\Form\Extension\Core\Type\RepeatedType; |
| 11 | use Symfony\Component\Form\FormBuilderInterface; |
| 12 | use Symfony\Component\OptionsResolver\OptionsResolver; |
| 13 | use Symfony\Component\Validator\Constraints\IsTrue; |
| 14 | use Symfony\Component\Validator\Constraints\Length; |
| 15 | |
| 16 | class RegistrationFormType extends AbstractType |
| 17 | { |
| 18 | public function buildForm(FormBuilderInterface $builder, array $options): void |
| 19 | { |
| 20 | $builder |
| 21 | ->add(child: 'username') |
| 22 | ->add(child: 'email', type: EmailType::class) |
| 23 | ->add(child: 'password', type: RepeatedType::class, options: [ |
| 24 | 'type' => PasswordType::class, |
| 25 | 'invalid_message' => 'The password fields must match.', |
| 26 | 'options' => ['attr' => ['class' => 'password-field']], |
| 27 | 'required' => true, |
| 28 | 'first_options' => ['label' => 'Password'], |
| 29 | 'second_options' => ['label' => 'Repeat Password'], |
| 30 | 'constraints' => [new Length(exactly: ['min' => 6])] |
| 31 | ]) |
| 32 | ->add(child: 'agreeTerms', type: CheckboxType::class, options: [ |
| 33 | 'mapped' => false, |
| 34 | 'constraints' => [ |
| 35 | new IsTrue(options: [ |
| 36 | 'message' => 'You should agree to our terms.', |
| 37 | ]), |
| 38 | ], |
| 39 | ]) |
| 40 | ; |
| 41 | } |
| 42 | |
| 43 | public function configureOptions(OptionsResolver $resolver): void |
| 44 | { |
| 45 | $resolver->setDefaults(defaults: [ |
| 46 | 'data_class' => User::class, |
| 47 | ]); |
| 48 | } |
| 49 | } |