Repository navigation
Expand file tree
/
Copy pathUserFormType.php
More file actions
67 lines (62 loc) · 1.98 KB
/
Copy pathUserFormType.php
File metadata and controls
67 lines (62 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace SyncEngine\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Contracts\Translation\TranslatorInterface;
use SyncEngine\Entity\User;
/**
* User editing form type, meant for Admins editing other users.
*/
class UserFormType extends AbstractType
{
public function __construct( private readonly TranslatorInterface $translator ) {}
public function buildForm( FormBuilderInterface $builder, array $options ): void
{
$builder
->add('email', TextType::class, [
'row_attr' => [
'class' => 'form-floating mb-3',
],
])
->add('name', TextType::class, [
'row_attr' => [
'class' => 'form-floating mb-3',
],
])
->add('plainPassword', PasswordType::class, [
'label' => $this->translator->trans( 'New password' ),
'row_attr' => [
'class' => 'form-floating mb-3',
],
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
'required' => false,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new Length( min: 6, max: 4096, minMessage: 'Your password should be at least { limit } characters' ),
],
])
->add( 'roles', ChoiceType::class, [
'label' => $this->translator->trans( 'Roles' ),
'choices' => [
$this->translator->trans( 'Admin' ) => 'ROLE_ADMIN',
$this->translator->trans( 'Editor' ) => 'ROLE_EDITOR',
$this->translator->trans( 'Viewer' ) => 'ROLE_VIEWER',
],
'multiple' => true,
'expanded' => true,
] );
}
public function configureOptions( OptionsResolver $resolver ): void
{
$resolver->setDefaults( [
'data_class' => User::class,
] );
}
}