1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PiouPiou\RibsAdminBundle\Form; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
6
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
7
|
|
|
use Symfony\Component\Form\AbstractType; |
8
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
9
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
10
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
11
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
12
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
13
|
|
|
|
14
|
|
|
class User extends AbstractType |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var EntityManagerInterface |
18
|
|
|
*/ |
19
|
|
|
private $em; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var TokenStorageInterface |
23
|
|
|
*/ |
24
|
|
|
private $tokenStorage; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* User constructor. |
28
|
|
|
* @param EntityManagerInterface $em |
29
|
|
|
* @param TokenStorageInterface $tokenStorage |
30
|
|
|
*/ |
31
|
|
|
public function __construct(EntityManagerInterface $em, TokenStorageInterface $tokenStorage) |
32
|
|
|
{ |
33
|
|
|
$this->em = $em; |
34
|
|
|
$this->tokenStorage = $tokenStorage; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param FormBuilderInterface $builder |
39
|
|
|
* @param array $options |
40
|
|
|
*/ |
41
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
42
|
|
|
{ |
43
|
|
|
$access_rights_lists = $this->em->getRepository(\PiouPiou\RibsAdminBundle\Entity\AccessRight::class)->findAll(); |
44
|
|
|
|
45
|
|
|
$builder |
46
|
|
|
->add('firstname', TextType::class, [ |
47
|
|
|
'label' => 'Firstname', |
48
|
|
|
'attr' => [], |
49
|
|
|
'required' => true |
50
|
|
|
]) |
51
|
|
|
->add('lastname', TextType::class, [ |
52
|
|
|
'label' => 'lastname', |
53
|
|
|
'attr' => [], |
54
|
|
|
'required' => true |
55
|
|
|
]) |
56
|
|
|
->add('admin', CheckboxType::class, [ |
57
|
|
|
'label' => 'Access to administration', |
58
|
|
|
'attr' => [ |
59
|
|
|
'class' => 'ribs-checkbox switched' |
60
|
|
|
], |
61
|
|
|
'required' => false |
62
|
|
|
]) |
63
|
|
|
->add("AccessRightList", EntityType::class, [ |
64
|
|
|
"label" => "Select an access right list for the user", |
65
|
|
|
"choices" => $access_rights_lists, |
66
|
|
|
"choice_label" => 'name', |
67
|
|
|
"class" => \PiouPiou\RibsAdminBundle\Entity\AccessRight::class, |
68
|
|
|
"multiple" => false, |
69
|
|
|
"required" => false |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param OptionsResolver $resolver |
75
|
|
|
*/ |
76
|
|
|
public function configureOptions(OptionsResolver $resolver) |
77
|
|
|
{ |
78
|
|
|
$resolver->setDefaults([ |
79
|
|
|
'data_class' => \PiouPiou\RibsAdminBundle\Entity\User::class, |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|