1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys UserBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\UserBundle\Form
;
14 use Symfony\Component\Form\AbstractType
;
15 use Symfony\Component\Form\Extension\Core\Type\EmailType
;
16 use Symfony\Component\Form\Extension\Core\Type\PasswordType
;
17 use Symfony\Component\Form\Extension\Core\Type\RepeatedType
;
18 use Symfony\Component\Form\Extension\Core\Type\SubmitType
;
19 use Symfony\Component\Form\FormBuilderInterface
;
20 use Symfony\Component\OptionsResolver\OptionsResolver
;
21 use Symfony\Component\Validator\Constraints\Email
;
22 use Symfony\Component\Validator\Constraints\NotBlank
;
24 class LoginType
extends AbstractType
{
28 public function buildForm(FormBuilderInterface
$builder, array $options): FormBuilderInterface
{
32 //Add extra mail field
33 if (!empty($options['mail'])) {
34 $form->add('mail', EmailType
::class, ['attr' => ['placeholder' => 'Your mail'], 'constraints' => [new NotBlank(['message' => 'Please provide your mail']), new Email(['message' => 'Your mail doesn\'t seems to be valid'])]]);
37 //Add extra password field
38 if (!empty($options['password'])) {
39 //Add password repeated field
40 if (!empty($options['password_repeated'])) {
41 $form->add('password', RepeatedType
::class, ['type' => PasswordType
::class, 'invalid_message' => 'The password and confirmation must match', 'first_options' => ['attr' => ['placeholder' => 'Your password'], 'label' => 'Password'], 'second_options' => ['attr' => ['placeholder' => 'Your password confirmation'], 'label' => 'Confirm password'], 'options' => ['constraints' => [new NotBlank(['message' => 'Please provide your password'])]]]);
44 $form->add('password', PasswordType
::class, ['attr' => ['placeholder' => 'Your password'], 'constraints' => [new NotBlank(['message' => 'Please provide your password'])]]);
49 $form->add('submit', SubmitType
::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
58 public function configureOptions(OptionsResolver
$resolver): void {
60 $resolver->setDefaults(['error_bubbling' => true, 'mail' => true, 'password' => true, 'password_repeated' => true]);
62 //Add extra mail option
63 $resolver->setAllowedTypes('mail', 'boolean');
65 //Add extra password option
66 $resolver->setAllowedTypes('password', 'boolean');
68 //Add extra password repeated option
69 $resolver->setAllowedTypes('password_repeated', 'boolean');
75 public function getName(): string {
76 return 'rapsys_user_login';