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
;
16 use Rapsys\UserBundle\Entity\Civility
;
18 class RegisterType
extends AbstractType
{
22 public function buildForm(FormBuilderInterface
$builder, array $options) {
25 //Add extra mail field
26 if (!empty($options['mail'])) {
27 $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'])]]);
30 $form->add('civility', EntityType
::class, ['class' => $options['class_civility'], 'attr' => ['placeholder' => 'Your civility'], 'constraints' => [new NotBlank(['message' => 'Please provide your civility'])], 'choice_translation_domain' => true, 'data' => $options['civility']])
31 ->add('pseudonym', TextType
::class, ['attr' => ['placeholder' => 'Your pseudonym'], 'constraints' => [new NotBlank(['message' => 'Please provide your pseudonym'])]])
32 ->add('forename', TextType
::class, ['attr' => ['placeholder' => 'Your forename'], 'constraints' => [new NotBlank(['message' => 'Please provide your forename'])]])
33 ->add('surname', TextType
::class, ['attr' => ['placeholder' => 'Your surname'], 'constraints' => [new NotBlank(['message' => 'Please provide your surname'])]]);
35 //Add extra password field
36 if (!empty($options['password'])) {
37 $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'])]]]);
41 $form->add('submit', SubmitType
::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
50 public function configureOptions(OptionsResolver
$resolver) {
51 $resolver->setDefaults(['error_bubbling' => true, 'class_civility' => 'RapsysUserBundle:Civility', 'civility' => null, 'password' => true, 'mail' => true]);
52 $resolver->setAllowedTypes('class_civility', 'string');
53 $resolver->setAllowedTypes('civility', [Civility
::class, 'null']);
54 $resolver->setAllowedTypes('password', 'boolean');
55 $resolver->setAllowedTypes('mail', 'boolean');
61 public function getName() {
62 return 'rapsys_user_register';