|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ae\FeatureBundle\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Sonata\AdminBundle\Admin\Admin; |
|
6
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
|
7
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
|
8
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @author Carlo Forghieri <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class FeatureAdmin extends Admin |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
|
|
*/ |
|
18
|
|
|
protected function configureDatagridFilters(DatagridMapper $datagridMapper) |
|
19
|
|
|
{ |
|
20
|
|
|
$datagridMapper |
|
21
|
|
|
->add('name') |
|
22
|
|
|
->add('enabled'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function configureListFields(ListMapper $listMapper) |
|
29
|
|
|
{ |
|
30
|
|
|
$listMapper |
|
31
|
|
|
->add('id') |
|
32
|
|
|
->add('name') |
|
33
|
|
|
->add('role') |
|
34
|
|
|
->add('enabled') |
|
35
|
|
|
->add('_action', 'actions', [ |
|
36
|
|
|
'actions' => [ |
|
37
|
|
|
'edit' => [], |
|
38
|
|
|
'delete' => [], |
|
39
|
|
|
], |
|
40
|
|
|
]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function configureFormFields(FormMapper $formMapper) |
|
47
|
|
|
{ |
|
48
|
|
|
$roles = $this->getRoles(); |
|
49
|
|
|
|
|
50
|
|
|
$formMapper |
|
51
|
|
|
->add('name', 'text', [ |
|
52
|
|
|
'required' => true, |
|
53
|
|
|
]) |
|
54
|
|
|
->add('enabled', 'checkbox', [ |
|
55
|
|
|
'required' => false, |
|
56
|
|
|
]) |
|
57
|
|
|
->add('role', 'choice', [ |
|
58
|
|
|
'choices' => array_combine($roles, $roles), |
|
59
|
|
|
'multiple' => false, |
|
60
|
|
|
'required' => false, |
|
61
|
|
|
]); |
|
62
|
|
|
|
|
63
|
|
|
if (!$this->getSubject()->getParent()) { |
|
64
|
|
|
$formMapper->add( |
|
65
|
|
|
'children', |
|
66
|
|
|
'sonata_type_collection', |
|
67
|
|
|
[ |
|
68
|
|
|
'required' => false, |
|
69
|
|
|
], |
|
70
|
|
|
[ |
|
71
|
|
|
'edit' => 'inline', |
|
72
|
|
|
'inline' => 'table', |
|
73
|
|
|
] |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function getRoles() |
|
79
|
|
|
{ |
|
80
|
|
|
$roleHierarchy = $this |
|
81
|
|
|
->getConfigurationPool() |
|
82
|
|
|
->getContainer() |
|
83
|
|
|
->getParameter('security.role_hierarchy.roles'); |
|
84
|
|
|
|
|
85
|
|
|
$roles = array_keys($roleHierarchy); |
|
86
|
|
|
$roles[] = 'ROLE_PREVIOUS_ADMIN'; |
|
87
|
|
|
|
|
88
|
|
|
return $roles; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function createQuery($context = 'list') |
|
92
|
|
|
{ |
|
93
|
|
|
$query = parent::createQuery($context); |
|
94
|
|
|
if ($context === 'list') { |
|
95
|
|
|
$alias = current($query->getDQLPart('from'))->getAlias(); |
|
96
|
|
|
$query->andWhere($alias.'.parent IS NULL'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return $query; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function postUpdate($object) |
|
103
|
|
|
{ |
|
104
|
|
|
$manager = $this |
|
105
|
|
|
->getConfigurationPool() |
|
106
|
|
|
->getContainer() |
|
107
|
|
|
->get('ae_feature.manager'); |
|
108
|
|
|
|
|
109
|
|
|
foreach ($object->getChildren() as $child) { |
|
110
|
|
|
$manager->emptyCache( |
|
111
|
|
|
$child->getName(), |
|
112
|
|
|
$child |
|
113
|
|
|
->getParent() |
|
114
|
|
|
->getName() |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|