7
7
use Knp \Menu \ItemInterface as MenuItemInterface ;
8
8
use Sonata \AdminBundle \Admin \AbstractAdminExtension ;
9
9
use Sonata \AdminBundle \Admin \AdminInterface ;
10
- use Sonata \AdminBundle \Route \RouteCollection ;
10
+ use Sonata \AdminBundle \Route \RouteCollectionInterface ;
11
11
use Symfony \Component \OptionsResolver \OptionsResolver ;
12
12
use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
13
13
use Symfony \Component \Workflow \Exception \InvalidArgumentException ;
20
20
*/
21
21
class WorkflowExtension extends AbstractAdminExtension
22
22
{
23
- /**
24
- * @var Registry
25
- */
26
- private $ registry ;
23
+ private Registry $ registry ;
24
+ private array $ options ;
27
25
28
- /**
29
- * @var array
30
- */
31
- private $ options ;
32
-
33
- /**
34
- * @param Registry $registry
35
- * @param array $options
36
- */
37
26
public function __construct (Registry $ registry , array $ options = [])
38
27
{
39
28
$ this ->registry = $ registry ;
@@ -44,7 +33,7 @@ public function __construct(Registry $registry, array $options = [])
44
33
/**
45
34
* @inheritdoc
46
35
*/
47
- public function configureRoutes (AdminInterface $ admin , RouteCollection $ collection ): void
36
+ public function configureRoutes (AdminInterface $ admin , RouteCollectionInterface $ collection ): void
48
37
{
49
38
$ collection ->add (
50
39
'workflow_apply_transition ' ,
@@ -69,18 +58,23 @@ public function alterNewInstance(AdminInterface $admin, $object): void
69
58
/**
70
59
* @inheritdoc
71
60
*/
72
- public function configureSideMenu (
61
+ public function configureTabMenu (
73
62
AdminInterface $ admin ,
74
63
MenuItemInterface $ menu ,
75
64
$ action ,
76
- AdminInterface $ childAdmin = null
65
+ ? AdminInterface $ childAdmin = null
77
66
): void {
78
67
if (null !== $ childAdmin || !in_array ($ action , $ this ->options ['render_actions ' ], true )) {
79
68
return ;
80
69
}
81
70
82
- $ subject = $ admin ->getSubject ();
83
- if (null === $ subject || !$ this ->isGrantedView ($ admin , $ subject )) {
71
+ try {
72
+ $ subject = $ admin ->getSubject ();
73
+ } catch (\LogicException $ exception ) {
74
+ return ;
75
+ }
76
+
77
+ if (!$ this ->isGrantedView ($ admin , $ subject )) {
84
78
return ;
85
79
}
86
80
@@ -111,20 +105,13 @@ public function getAccessMapping(AdminInterface $admin): array
111
105
}
112
106
113
107
/**
114
- * @param object $subject
115
- * @param string|null $workflowName
116
- *
117
- * @return Workflow
118
108
* @throws InvalidArgumentException
119
109
*/
120
- protected function getWorkflow ($ subject , string $ workflowName = null ): Workflow
110
+ protected function getWorkflow (object $ subject , string $ workflowName = null ): Workflow
121
111
{
122
112
return $ this ->registry ->get ($ subject , $ workflowName );
123
113
}
124
114
125
- /**
126
- * @param OptionsResolver $resolver
127
- */
128
115
protected function configureOptions (OptionsResolver $ resolver ): void
129
116
{
130
117
$ resolver
@@ -155,10 +142,6 @@ protected function configureOptions(OptionsResolver $resolver): void
155
142
;
156
143
}
157
144
158
- /**
159
- * @param MenuItemInterface $menu
160
- * @param AdminInterface $admin
161
- */
162
145
protected function noTransitions (MenuItemInterface $ menu , AdminInterface $ admin ): void
163
146
{
164
147
if ($ this ->options ['no_transition_display ' ]) {
@@ -175,16 +158,13 @@ protected function noTransitions(MenuItemInterface $menu, AdminInterface $admin)
175
158
}
176
159
177
160
/**
178
- * @param MenuItemInterface $menu
179
- * @param AdminInterface $admin
180
- * @param iterable|Transition[] $transitions
181
- * @param object $subject
161
+ * @param iterable&Transition[] $transitions
182
162
*/
183
163
protected function transitionsDropdown (
184
164
MenuItemInterface $ menu ,
185
165
AdminInterface $ admin ,
186
166
iterable $ transitions ,
187
- $ subject
167
+ object $ subject
188
168
): void {
189
169
$ workflowMenu = $ menu ->addChild ($ this ->options ['dropdown_transitions_label ' ], [
190
170
'attributes ' => [
@@ -201,17 +181,11 @@ protected function transitionsDropdown(
201
181
}
202
182
}
203
183
204
- /**
205
- * @param MenuItemInterface $menu
206
- * @param AdminInterface $admin
207
- * @param Transition $transition
208
- * @param object $subject
209
- */
210
184
protected function transitionsItem (
211
185
MenuItemInterface $ menu ,
212
186
AdminInterface $ admin ,
213
187
Transition $ transition ,
214
- $ subject
188
+ object $ subject
215
189
): void {
216
190
$ options = [
217
191
'attributes ' => [],
@@ -234,11 +208,6 @@ protected function transitionsItem(
234
208
);
235
209
}
236
210
237
- /**
238
- * @param Transition $transition
239
- *
240
- * @return string|null
241
- */
242
211
protected function getTransitionIcon (Transition $ transition ): ?string
243
212
{
244
213
if (isset ($ this ->options ['transitions_icons ' ][$ transition ->getName ()])) {
@@ -248,14 +217,7 @@ protected function getTransitionIcon(Transition $transition): ?string
248
217
return $ this ->options ['transitions_default_icon ' ];
249
218
}
250
219
251
- /**
252
- * @param AdminInterface $admin
253
- * @param Transition $transition
254
- * @param object $subject
255
- *
256
- * @return string
257
- */
258
- protected function generateTransitionUri (AdminInterface $ admin , Transition $ transition , $ subject ): string
220
+ protected function generateTransitionUri (AdminInterface $ admin , Transition $ transition , object $ subject ): string
259
221
{
260
222
return $ admin ->generateObjectUrl (
261
223
'workflow_apply_transition ' ,
@@ -264,13 +226,7 @@ protected function generateTransitionUri(AdminInterface $admin, Transition $tran
264
226
);
265
227
}
266
228
267
- /**
268
- * @param AdminInterface $admin
269
- * @param object $subject
270
- *
271
- * @return bool
272
- */
273
- protected function isGrantedView (AdminInterface $ admin , $ subject ): bool
229
+ protected function isGrantedView (AdminInterface $ admin , object $ subject ): bool
274
230
{
275
231
try {
276
232
$ admin ->checkAccess ('viewTransitions ' , $ subject );
@@ -281,13 +237,7 @@ protected function isGrantedView(AdminInterface $admin, $subject): bool
281
237
return true ;
282
238
}
283
239
284
- /**
285
- * @param AdminInterface $admin
286
- * @param object $subject
287
- *
288
- * @return bool
289
- */
290
- protected function isGrantedApply (AdminInterface $ admin , $ subject ): bool
240
+ protected function isGrantedApply (AdminInterface $ admin , object $ subject ): bool
291
241
{
292
242
try {
293
243
$ admin ->checkAccess ('applyTransitions ' , $ subject );
0 commit comments