]>
Commit | Line | Data |
---|---|---|
152fcccd JB |
1 | <?php |
2 | ||
3 | namespace Wallabag\UserBundle\Form; | |
4 | ||
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\Extension\Core\Type\TextType; | |
11 | use Symfony\Component\Form\FormBuilderInterface; | |
12 | use Symfony\Component\OptionsResolver\OptionsResolver; | |
13 | use Symfony\Component\Validator\Constraints; | |
14 | ||
15 | class NewUserType extends AbstractType | |
16 | { | |
17 | public function buildForm(FormBuilderInterface $builder, array $options) | |
18 | { | |
19 | $builder | |
20 | ->add('username', TextType::class, [ | |
21 | 'required' => true, | |
22 | 'label' => 'user.form.username_label', | |
23 | ]) | |
24 | ->add('plainPassword', RepeatedType::class, [ | |
25 | 'type' => PasswordType::class, | |
26 | 'invalid_message' => 'validator.password_must_match', | |
27 | 'first_options' => ['label' => 'user.form.password_label'], | |
28 | 'second_options' => ['label' => 'user.form.repeat_new_password_label'], | |
29 | 'constraints' => [ | |
30 | new Constraints\Length([ | |
31 | 'min' => 8, | |
32 | 'minMessage' => 'validator.password_too_short', | |
33 | ]), | |
34 | new Constraints\NotBlank(), | |
35 | ], | |
36 | 'label' => 'user.form.plain_password_label', | |
37 | ]) | |
38 | ->add('email', EmailType::class, [ | |
39 | 'label' => 'user.form.email_label', | |
40 | ]) | |
41 | ->add('save', SubmitType::class, [ | |
42 | 'label' => 'user.form.save', | |
43 | ]) | |
44 | ; | |
45 | } | |
46 | ||
47 | public function configureOptions(OptionsResolver $resolver) | |
48 | { | |
49 | $resolver->setDefaults([ | |
50 | 'data_class' => 'Wallabag\UserBundle\Entity\User', | |
51 | ]); | |
52 | } | |
53 | ||
54 | public function getBlockPrefix() | |
55 | { | |
56 | return 'new_user'; | |
57 | } | |
58 | } |