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