]> Raphaƫl G. Git Repositories - userbundle/blob - Form/RegisterType.php
11ec089671722a07858a21ceee66becfc8538781
[userbundle] / Form / RegisterType.php
1 <?php
2
3 namespace Rapsys\UserBundle\Form;
4
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\Title;
17
18 class RegisterType extends AbstractType {
19 /**
20 * {@inheritdoc}
21 */
22 public function buildForm(FormBuilderInterface $builder, array $options) {
23 return $builder
24 ->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'])]])
25 ->add('title', EntityType::class, ['class' => $options['class_title'], 'attr' => ['placeholder' => 'Your title'], 'constraints' => [new NotBlank(['message' => 'Please provide your title'])], 'choice_translation_domain' => true, 'data' => $options['title']])
26 ->add('pseudonym', TextType::class, ['attr' => ['placeholder' => 'Your pseudonym'], 'constraints' => [new NotBlank(['message' => 'Please provide your pseudonym'])]])
27 ->add('forename', TextType::class, ['attr' => ['placeholder' => 'Your forename'], 'constraints' => [new NotBlank(['message' => 'Please provide your forename'])]])
28 ->add('surname', TextType::class, ['attr' => ['placeholder' => 'Your surname'], 'constraints' => [new NotBlank(['message' => 'Please provide your surname'])]])
29 ->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'])]]])
30 ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
31 }
32
33 /**
34 * {@inheritdoc}
35 */
36 public function configureOptions(OptionsResolver $resolver) {
37 $resolver->setDefaults(['error_bubbling' => true, 'class_title' => 'RapsysUserBundle:Title', 'title' => null]);
38 $resolver->setAllowedTypes('class_title', 'string');
39 $resolver->setAllowedTypes('title', [Title::class, 'null']);
40 }
41
42 /**
43 * {@inheritdoc}
44 */
45 public function getName() {
46 return 'rapsys_user_register';
47 }
48 }