|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ProjetNormandie\UserBundle\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
|
6
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
|
7
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
|
8
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
|
9
|
|
|
use Sonata\AdminBundle\Route\RouteCollectionInterface; |
|
10
|
|
|
use Sonata\AdminBundle\Show\ShowMapper; |
|
11
|
|
|
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType; |
|
12
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
|
13
|
|
|
use Symfony\Component\Form\Extension\Core\Type\EmailType; |
|
14
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
|
16
|
|
|
|
|
17
|
|
|
class UserAdmin extends AbstractAdmin |
|
18
|
|
|
{ |
|
19
|
|
|
protected $baseRouteName = 'pnu_admin_user'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param RouteCollectionInterface $collection |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function configureRoutes(RouteCollectionInterface $collection): void |
|
25
|
|
|
{ |
|
26
|
|
|
$collection |
|
27
|
|
|
->remove('create') |
|
28
|
|
|
->remove('export') |
|
29
|
|
|
->remove('delete'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param FormMapper $form |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function configureFormFields(FormMapper $form): void |
|
36
|
|
|
{ |
|
37
|
|
|
$form |
|
38
|
|
|
->add('username', TextType::class, [ |
|
39
|
|
|
'label' => 'user.form.username', |
|
40
|
|
|
'required' => true, |
|
41
|
|
|
]) |
|
42
|
|
|
->add('email', EmailType::class, [ |
|
43
|
|
|
'label' => 'user.form.email', |
|
44
|
|
|
'required' => true, |
|
45
|
|
|
]) |
|
46
|
|
|
->add('groups', ModelAutocompleteType::class, [ |
|
47
|
|
|
'label' => 'user.form.groups', |
|
48
|
|
|
'property' => 'name', |
|
49
|
|
|
'required' => false, |
|
50
|
|
|
'multiple' => true, |
|
51
|
|
|
'btn_add' => false, |
|
52
|
|
|
]) |
|
53
|
|
|
->add('enabled', CheckboxType::class, [ |
|
54
|
|
|
'required' => false, |
|
55
|
|
|
'label' => 'user.form.enabled' |
|
56
|
|
|
]) |
|
57
|
|
|
->add('comment', TextareaType::class, [ |
|
58
|
|
|
'required' => false, |
|
59
|
|
|
'label' => 'user.form.comment' |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param DatagridMapper $filter |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function configureDatagridFilters(DatagridMapper $filter): void |
|
67
|
|
|
{ |
|
68
|
|
|
$filter |
|
69
|
|
|
->add('username', null, ['label' => 'user.filter.username']) |
|
70
|
|
|
->add('email', null, ['label' => 'user.filter.email']) |
|
71
|
|
|
->add('enabled', null, ['label' => 'user.filter.enabled']) |
|
72
|
|
|
->add('groups', null, ['label' => 'user.filter.groups']); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param ListMapper $list |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function configureListFields(ListMapper $list): void |
|
79
|
|
|
{ |
|
80
|
|
|
$list |
|
81
|
|
|
->addIdentifier('id', null, ['label' => 'user.list.id']) |
|
82
|
|
|
->add('username', null, ['label' => 'user.list.username']) |
|
83
|
|
|
->add('email', null, ['label' => 'user.list.email']) |
|
84
|
|
|
->add('groups', null, ['label' => 'user.list.groups']) |
|
85
|
|
|
->add('enabled', null, ['editable' => true, 'label' => 'user.list.enabled']) |
|
86
|
|
|
->add('_action', 'actions', [ |
|
87
|
|
|
'actions' => [ |
|
88
|
|
|
'show' => [], |
|
89
|
|
|
'edit' => [], |
|
90
|
|
|
] |
|
91
|
|
|
]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param ShowMapper $show |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function configureShowFields(ShowMapper $show): void |
|
98
|
|
|
{ |
|
99
|
|
|
$show |
|
100
|
|
|
->with('User', ['class' => 'col-md-6']) |
|
101
|
|
|
->add('id', null, ['label' => 'user.show.id']) |
|
102
|
|
|
->add('username', null, ['label' => 'user.show.username']) |
|
103
|
|
|
->add('email', null, ['label' => 'user.show.email']) |
|
104
|
|
|
->add('enabled', null, ['label' => 'user.show.enabled']) |
|
105
|
|
|
->add('language', null, ['label' => 'user.show.language']) |
|
106
|
|
|
->add('avatar', null, ['label' => 'user.show.avatar']) |
|
107
|
|
|
->add('nbConnexion', null, ['label' => 'user.show.nb_connexion']) |
|
108
|
|
|
->add('extraData', null, ['label' => 'user.show.extra_data']) |
|
109
|
|
|
->add('comment', null, ['label' => 'user.show.comment']) |
|
110
|
|
|
->end() |
|
111
|
|
|
->with('Connexion', ['class' => 'col-md-6']) |
|
112
|
|
|
->add('lastLogin', null, ['label' => 'user.show.last_login']) |
|
113
|
|
|
->add('password', null, ['label' => 'user.show.password']) |
|
114
|
|
|
->add('confirmationToken', null, ['label' => 'user.show.confirmation_token']) |
|
115
|
|
|
->add('passwordRequestedAt', 'datetime', ['label' => 'user.show.password_requested_at']) |
|
116
|
|
|
->end(); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|