|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FSi\Bundle\AdminSecurityBundle\Doctrine\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement; |
|
6
|
|
|
use FSi\Bundle\AdminSecurityBundle\Form\TypeSolver; |
|
7
|
|
|
use FSi\Component\DataGrid\DataGridFactoryInterface; |
|
8
|
|
|
use FSi\Component\DataGrid\DataGridInterface; |
|
9
|
|
|
use FSi\Component\DataSource\DataSourceFactoryInterface; |
|
10
|
|
|
use FSi\Component\DataSource\DataSourceInterface; |
|
11
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
12
|
|
|
use Symfony\Component\Form\FormInterface; |
|
13
|
|
|
|
|
14
|
|
|
class UserElement extends CRUDElement |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
private $userModel; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $formClass; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(array $options, string $userModel, string $formClass) |
|
27
|
|
|
{ |
|
28
|
|
|
parent::__construct($options); |
|
29
|
|
|
$this->userModel = $userModel; |
|
30
|
|
|
$this->formClass = $formClass; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getId(): string |
|
37
|
|
|
{ |
|
38
|
|
|
return 'admin_security_user'; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getClassName(): string |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->userModel; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface |
|
53
|
|
|
{ |
|
54
|
|
|
return $factory->createDataGrid('admin_security_user'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function initDataSource(DataSourceFactoryInterface $factory): DataSourceInterface |
|
61
|
|
|
{ |
|
62
|
|
|
return $factory->createDataSource( |
|
63
|
|
|
'doctrine-orm', |
|
64
|
|
|
['entity' => $this->getClassName()], |
|
65
|
|
|
$this->getId() |
|
66
|
|
|
)->setMaxResults(20); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface |
|
73
|
|
|
{ |
|
74
|
|
|
$formType = TypeSolver::getFormType($this->formClass, 'admin_user'); |
|
75
|
|
|
return $factory->create($formType, $data); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|