77use Knp \Menu \ItemInterface as MenuItemInterface ;
88use Sonata \AdminBundle \Admin \AbstractAdminExtension ;
99use Sonata \AdminBundle \Admin \AdminInterface ;
10- use Sonata \AdminBundle \Route \RouteCollection ;
10+ use Sonata \AdminBundle \Route \RouteCollectionInterface ;
1111use Symfony \Component \OptionsResolver \OptionsResolver ;
1212use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
1313use Symfony \Component \Workflow \Exception \InvalidArgumentException ;
2020 */
2121class WorkflowExtension extends AbstractAdminExtension
2222{
23- /**
24- * @var Registry
25- */
26- private $ registry ;
23+ private Registry $ registry ;
24+ private array $ options ;
2725
28- /**
29- * @var array
30- */
31- private $ options ;
32-
33- /**
34- * @param Registry $registry
35- * @param array $options
36- */
3726 public function __construct (Registry $ registry , array $ options = [])
3827 {
3928 $ this ->registry = $ registry ;
@@ -44,7 +33,7 @@ public function __construct(Registry $registry, array $options = [])
4433 /**
4534 * @inheritdoc
4635 */
47- public function configureRoutes (AdminInterface $ admin , RouteCollection $ collection ): void
36+ public function configureRoutes (AdminInterface $ admin , RouteCollectionInterface $ collection ): void
4837 {
4938 $ collection ->add (
5039 'workflow_apply_transition ' ,
@@ -69,18 +58,23 @@ public function alterNewInstance(AdminInterface $admin, $object): void
6958 /**
7059 * @inheritdoc
7160 */
72- public function configureSideMenu (
61+ public function configureTabMenu (
7362 AdminInterface $ admin ,
7463 MenuItemInterface $ menu ,
7564 $ action ,
76- AdminInterface $ childAdmin = null
65+ ? AdminInterface $ childAdmin = null
7766 ): void {
7867 if (null !== $ childAdmin || !in_array ($ action , $ this ->options ['render_actions ' ], true )) {
7968 return ;
8069 }
8170
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 )) {
8478 return ;
8579 }
8680
@@ -111,20 +105,13 @@ public function getAccessMapping(AdminInterface $admin): array
111105 }
112106
113107 /**
114- * @param object $subject
115- * @param string|null $workflowName
116- *
117- * @return Workflow
118108 * @throws InvalidArgumentException
119109 */
120- protected function getWorkflow ($ subject , string $ workflowName = null ): Workflow
110+ protected function getWorkflow (object $ subject , string $ workflowName = null ): Workflow
121111 {
122112 return $ this ->registry ->get ($ subject , $ workflowName );
123113 }
124114
125- /**
126- * @param OptionsResolver $resolver
127- */
128115 protected function configureOptions (OptionsResolver $ resolver ): void
129116 {
130117 $ resolver
@@ -155,10 +142,6 @@ protected function configureOptions(OptionsResolver $resolver): void
155142 ;
156143 }
157144
158- /**
159- * @param MenuItemInterface $menu
160- * @param AdminInterface $admin
161- */
162145 protected function noTransitions (MenuItemInterface $ menu , AdminInterface $ admin ): void
163146 {
164147 if ($ this ->options ['no_transition_display ' ]) {
@@ -175,16 +158,13 @@ protected function noTransitions(MenuItemInterface $menu, AdminInterface $admin)
175158 }
176159
177160 /**
178- * @param MenuItemInterface $menu
179- * @param AdminInterface $admin
180- * @param iterable|Transition[] $transitions
181- * @param object $subject
161+ * @param iterable&Transition[] $transitions
182162 */
183163 protected function transitionsDropdown (
184164 MenuItemInterface $ menu ,
185165 AdminInterface $ admin ,
186166 iterable $ transitions ,
187- $ subject
167+ object $ subject
188168 ): void {
189169 $ workflowMenu = $ menu ->addChild ($ this ->options ['dropdown_transitions_label ' ], [
190170 'attributes ' => [
@@ -201,17 +181,11 @@ protected function transitionsDropdown(
201181 }
202182 }
203183
204- /**
205- * @param MenuItemInterface $menu
206- * @param AdminInterface $admin
207- * @param Transition $transition
208- * @param object $subject
209- */
210184 protected function transitionsItem (
211185 MenuItemInterface $ menu ,
212186 AdminInterface $ admin ,
213187 Transition $ transition ,
214- $ subject
188+ object $ subject
215189 ): void {
216190 $ options = [
217191 'attributes ' => [],
@@ -234,11 +208,6 @@ protected function transitionsItem(
234208 );
235209 }
236210
237- /**
238- * @param Transition $transition
239- *
240- * @return string|null
241- */
242211 protected function getTransitionIcon (Transition $ transition ): ?string
243212 {
244213 if (isset ($ this ->options ['transitions_icons ' ][$ transition ->getName ()])) {
@@ -248,14 +217,7 @@ protected function getTransitionIcon(Transition $transition): ?string
248217 return $ this ->options ['transitions_default_icon ' ];
249218 }
250219
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
259221 {
260222 return $ admin ->generateObjectUrl (
261223 'workflow_apply_transition ' ,
@@ -264,13 +226,7 @@ protected function generateTransitionUri(AdminInterface $admin, Transition $tran
264226 );
265227 }
266228
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
274230 {
275231 try {
276232 $ admin ->checkAccess ('viewTransitions ' , $ subject );
@@ -281,13 +237,7 @@ protected function isGrantedView(AdminInterface $admin, $subject): bool
281237 return true ;
282238 }
283239
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
291241 {
292242 try {
293243 $ admin ->checkAccess ('applyTransitions ' , $ subject );
0 commit comments