1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PiedWeb\CMSBundle\Admin; |
4
|
|
|
|
5
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
6
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
7
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
8
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
9
|
|
|
use Sonata\AdminBundle\Form\Type\ModelType; |
10
|
|
|
use Sonata\CoreBundle\Form\Type\ImmutableArrayType; |
11
|
|
|
use Sonata\CoreBundle\Form\Type\DatePickerType; |
12
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
13
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
14
|
|
|
use Sonata\UserBundle\Form\Type\SecurityRolesType; |
|
|
|
|
15
|
|
|
|
16
|
|
|
class UserAdmin extends AbstractAdmin |
17
|
|
|
{ |
18
|
|
|
protected $datagridValues = [ |
19
|
|
|
'_page' => 1, |
20
|
|
|
'_sort_order' => 'DESC', |
21
|
|
|
'_sort_by' => 'createdAt', |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
protected function configureFormFields(FormMapper $formMapper): void |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
$now = new \DateTime(); |
28
|
|
|
|
29
|
|
|
$formMapper |
30
|
|
|
->with('admin.user.label.id', ['class' => 'col-md-4']) |
31
|
|
|
//->add('username') |
32
|
|
|
->add('email', null, [ |
33
|
|
|
'label' => 'admin.user.email.label', |
34
|
|
|
]) |
35
|
|
|
->add('plainPassword', TextType::class, [ |
36
|
|
|
'required' => (!$this->getSubject() || null === $this->getSubject()->getId()), |
37
|
|
|
'label' => 'admin.user.password.label', |
38
|
|
|
]) |
39
|
|
|
->end() |
40
|
|
|
; |
41
|
|
|
|
42
|
|
|
$formMapper |
43
|
|
|
->with('admin.user.label.profile', ['class' => 'col-md-4']) |
44
|
|
|
; |
45
|
|
|
|
46
|
|
|
if (method_exists($this->getConfigurationPool()->getContainer()->getParameter('app.entity_user'), 'getDateOfBirth')) { |
47
|
|
|
$formMapper->add('dateOfBirth', DatePickerType::class, [ |
48
|
|
|
'years' => range(1900, $now->format('Y')), |
49
|
|
|
'dp_min_date' => '1-1-1900', |
50
|
|
|
'dp_max_date' => $now->format('c'), |
51
|
|
|
'required' => false, |
52
|
|
|
'label' => 'admin.user.dateOfBirth.label', |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
if (method_exists($this->getConfigurationPool()->getContainer()->getParameter('app.entity_user'), 'getfirstname')) { |
56
|
|
|
$formMapper->add('firstname', TextType::class, [ |
57
|
|
|
'required' => false, |
58
|
|
|
'label' => 'admin.user.firstname.label', |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
if (method_exists($this->getConfigurationPool()->getContainer()->getParameter('app.entity_user'), 'getlastname')) { |
62
|
|
|
$formMapper->add('lastname', TextType::class, [ |
63
|
|
|
'required' => false, |
64
|
|
|
'label' => 'admin.user.lastname.label', |
65
|
|
|
]); |
66
|
|
|
} |
67
|
|
|
if (method_exists($this->getConfigurationPool()->getContainer()->getParameter('app.entity_user'), 'getcity')) { |
68
|
|
|
$formMapper->add('city', TextType::class, [ |
69
|
|
|
'required' => false, |
70
|
|
|
'label' => 'admin.user.city.label', |
71
|
|
|
]); |
72
|
|
|
} |
73
|
|
|
if (method_exists($this->getConfigurationPool()->getContainer()->getParameter('app.entity_user'), 'getphone')) { |
74
|
|
|
$formMapper->add('phone', TextType::class, [ |
75
|
|
|
'required' => false, |
76
|
|
|
'label' => 'admin.user.phone.label', |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$formMapper->end() |
81
|
|
|
|
82
|
|
|
->with('admin.user.label.security', ['class' => 'col-md-4']) |
83
|
|
|
->add('enabled', null, [ |
84
|
|
|
'required' => false, |
85
|
|
|
'label' => 'admin.user.enabled.label', |
86
|
|
|
]) |
87
|
|
|
|
88
|
|
|
/* |
89
|
|
|
->with('Groups') |
90
|
|
|
->add('groups', ModelType::class, [ |
91
|
|
|
'required' => false, |
92
|
|
|
'expanded' => true, |
93
|
|
|
'multiple' => true, |
94
|
|
|
]) |
95
|
|
|
->end() |
96
|
|
|
*/ |
97
|
|
|
|
98
|
|
|
->add('roles', ImmutableArrayType::class, [ |
99
|
|
|
'label' => false, |
100
|
|
|
'keys' => [ |
101
|
|
|
['0', ChoiceType::class, [ |
102
|
|
|
'required' => false, |
103
|
|
|
'label' => 'admin.user.role.label', |
104
|
|
|
'choices' => [ |
105
|
|
|
'admin.user.role.admin' => 'ROLE_SUPER_ADMIN', |
106
|
|
|
'admin.user.role.user' => 'ROLE_USER', |
107
|
|
|
], |
108
|
|
|
]], |
109
|
|
|
], |
110
|
|
|
]) |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
->end() |
114
|
|
|
; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
protected function configureDatagridFilters(DatagridMapper $datagridMapper) |
118
|
|
|
{ |
119
|
|
|
$datagridMapper->add('id') |
120
|
|
|
->add('email') |
121
|
|
|
//->add('groups') |
122
|
|
|
; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
protected function configureListFields(ListMapper $listMapper) |
126
|
|
|
{ |
127
|
|
|
$listMapper |
128
|
|
|
->add('email', null, [ |
129
|
|
|
'label' => 'admin.user.email.label', |
130
|
|
|
]); |
131
|
|
|
if (method_exists($this->getConfigurationPool()->getContainer()->getParameter('app.entity_user'), 'getfirstname')) { |
132
|
|
|
$listMapper->add('firstname', TextType::class, [ |
133
|
|
|
'editable' => true, |
134
|
|
|
'label' => 'admin.user.firstname.label', |
135
|
|
|
]); |
136
|
|
|
} |
137
|
|
|
if (method_exists($this->getConfigurationPool()->getContainer()->getParameter('app.entity_user'), 'getlastname')) { |
138
|
|
|
$listMapper->add('lastname', TextType::class, [ |
139
|
|
|
'editable' => true, |
140
|
|
|
'label' => 'admin.user.lastname.label', |
141
|
|
|
]); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/**todo |
145
|
|
|
$listMapper->add('roles[0]', null, [ |
146
|
|
|
'label' => 'admin.user.role.label', |
147
|
|
|
]); |
148
|
|
|
/**/ |
149
|
|
|
$listMapper |
150
|
|
|
->add('enabled', null, [ |
151
|
|
|
'editable' => true, |
152
|
|
|
'label' => 'admin.user.enabled.label', |
153
|
|
|
]) |
154
|
|
|
->add('createdAt', null, [ |
155
|
|
|
'editable' => true, |
156
|
|
|
'label' => 'admin.user.createdAt.label', |
157
|
|
|
]) |
158
|
|
|
->add('_action', null, [ |
159
|
|
|
'actions' => [ |
160
|
|
|
'edit' => [], |
161
|
|
|
'delete' => [], |
162
|
|
|
], |
163
|
|
|
'row_align' => 'right', |
164
|
|
|
'header_class' => 'text-right', |
165
|
|
|
'label' => 'admin.action', |
166
|
|
|
]) |
167
|
|
|
; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths