3 namespace Rapsys\UserBundle\Form
; 
   5 use Symfony\Bridge\Doctrine\Form\Type\EntityType
; 
   6 use Symfony\Component\Form\AbstractType
; 
   7 use Symfony\Component\Form\Extension\Core\Type\EmailType
; 
   8 use Symfony\Component\Form\Extension\Core\Type\PasswordType
; 
   9 use Symfony\Component\Form\Extension\Core\Type\RepeatedType
; 
  10 use Symfony\Component\Form\Extension\Core\Type\SubmitType
; 
  11 use Symfony\Component\Form\Extension\Core\Type\TextType
; 
  12 use Symfony\Component\Form\FormBuilderInterface
; 
  13 use Symfony\Component\OptionsResolver\OptionsResolver
; 
  14 use Symfony\Component\Validator\Constraints\Email
; 
  15 use Symfony\Component\Validator\Constraints\NotBlank
; 
  17 use Rapsys\UserBundle\Entity\Civility
; 
  19 class RegisterType 
extends AbstractType 
{ 
  23         public function buildForm(FormBuilderInterface 
$builder, array $options) { 
  26                 //Add extra mail field 
  27                 if (!empty($options['mail'])) { 
  28                         $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'])]]); 
  31                 //Add extra civility field 
  32                 if (!empty($options['civility'])) { 
  33                         $form->add('civility', EntityType
::class, ['class' => $options['civility_class'], 'attr' => ['placeholder' => 'Your civility'], 'constraints' => [new NotBlank(['message' => 'Please provide your civility'])], 'choice_translation_domain' => true, 'data' => $options['civility_default']]); 
  36                 //Add extra pseudonym field 
  37                 if (!empty($options['pseudonym'])) { 
  38                         $form->add('pseudonym', TextType
::class, ['attr' => ['placeholder' => 'Your pseudonym'], 'constraints' => [new NotBlank(['message' => 'Please provide your pseudonym'])]]); 
  41                 //Add extra forename field 
  42                 if (!empty($options['forename'])) { 
  43                         $form->add('forename', TextType
::class, ['attr' => ['placeholder' => 'Your forename'], 'constraints' => [new NotBlank(['message' => 'Please provide your forename'])]]); 
  46                 //Add extra surname field 
  47                 if (!empty($options['surname'])) { 
  48                         $form->add('surname', TextType
::class, ['attr' => ['placeholder' => 'Your surname'], 'constraints' => [new NotBlank(['message' => 'Please provide your surname'])]]); 
  51                 //Add extra password field 
  52                 if (!empty($options['password'])) { 
  53                         $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'])]]]); 
  57                 $form->add('submit', SubmitType
::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]); 
  66         public function configureOptions(OptionsResolver 
$resolver) { 
  68                 $resolver->setDefaults(['error_bubbling' => true, 'civility_class' => 'RapsysUserBundle:Civility', 'civility_default' => null, 'mail' => true, 'civility' => true, 'pseudonym' => true, 'forename' => true, 'surname' => true, 'password' => true]); 
  71                 $resolver->setAllowedTypes('civility_class', 'string'); 
  73                 //Add civility default 
  74                 //XXX: trigger strange error about table not existing is not specified in form create 
  75                 $resolver->setAllowedTypes('civility_default', [Civility
::class, 'null']); 
  77                 //Add extra mail option 
  78                 $resolver->setAllowedTypes('mail', 'boolean'); 
  80                 //Add extra civility option 
  81                 $resolver->setAllowedTypes('civility', 'boolean'); 
  83                 //Add extra pseudonym option 
  84                 $resolver->setAllowedTypes('pseudonym', 'boolean'); 
  86                 //Add extra forename option 
  87                 $resolver->setAllowedTypes('forename', 'boolean'); 
  89                 //Add extra surname option 
  90                 $resolver->setAllowedTypes('surname', 'boolean'); 
  92                 //Add extra password option 
  93                 $resolver->setAllowedTypes('password', 'boolean'); 
 102         public function getName() { 
 103                 return 'rapsys_user_register';