3 namespace Rapsys\UserBundle\Form
; 
   5 use Symfony\Component\Form\AbstractType
; 
   6 use Symfony\Component\Form\Extension\Core\Type\EmailType
; 
   7 use Symfony\Component\Form\Extension\Core\Type\PasswordType
; 
   8 use Symfony\Component\Form\Extension\Core\Type\RepeatedType
; 
   9 use Symfony\Component\Form\Extension\Core\Type\SubmitType
; 
  10 use Symfony\Component\Form\FormBuilderInterface
; 
  11 use Symfony\Component\OptionsResolver\OptionsResolver
; 
  12 use Symfony\Component\Validator\Constraints\Email
; 
  13 use Symfony\Component\Validator\Constraints\NotBlank
; 
  15 class LoginType 
extends AbstractType 
{ 
  19         public function buildForm(FormBuilderInterface 
$builder, array $options) { 
  23                 //Add extra mail field 
  24                 if (!empty($options['mail'])) { 
  25                         $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'])]]); 
  28                 //Add extra password field 
  29                 if (!empty($options['password'])) { 
  30                         //Add password repeated field 
  31                         if (!empty($options['password_repeated'])) { 
  32                                 $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'])]]]); 
  35                                 $form->add('password', PasswordType
::class, ['attr' => ['placeholder' => 'Your password'], 'constraints' => [new NotBlank(['message' => 'Please provide your password'])]]); 
  40                 $form->add('submit', SubmitType
::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]); 
  49         public function configureOptions(OptionsResolver 
$resolver) { 
  51                 $resolver->setDefaults(['error_bubbling' => true, 'mail' => true, 'password' => true, 'password_repeated' => true]); 
  53                 //Add extra mail option 
  54                 $resolver->setAllowedTypes('mail', 'boolean'); 
  56                 //Add extra password option 
  57                 $resolver->setAllowedTypes('password', 'boolean'); 
  59                 //Add extra password repeated option 
  60                 $resolver->setAllowedTypes('password_repeated', 'boolean'); 
  66         public function getName() { 
  67                 return 'rapsys_user_login';