File tree Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -80,9 +80,8 @@ public function getItems(?string $area = null, string $key = ''): Collection
80
80
$ this ->prepareMenuItems ();
81
81
}
82
82
83
- $ items = collect ($ this ->items )->sortBy (fn ($ item ) => $ item ->getPosition ());
84
-
85
- return $ items ;
83
+ return collect ($ this ->removeUnauthorizedMenuItem ())
84
+ ->sortBy (fn ($ item ) => $ item ->getPosition ());
86
85
}
87
86
88
87
/**
@@ -185,4 +184,30 @@ private function findMatchingItem($items, $currentKey): ?MenuItem
185
184
186
185
return null ;
187
186
}
187
+
188
+ /**
189
+ * Remove unauthorized menu item.
190
+ */
191
+ private function removeUnauthorizedMenuItem (): array
192
+ {
193
+ return collect ($ this ->items )->map (function ($ item ) {
194
+ $ this ->removeChildrenUnauthorizedMenuItem ($ item );
195
+
196
+ return $ item ;
197
+ })->toArray ();
198
+ }
199
+
200
+ /**
201
+ * Remove unauthorized menuItem's children. This will handle all levels.
202
+ */
203
+ private function removeChildrenUnauthorizedMenuItem (MenuItem &$ menuItem ): void
204
+ {
205
+ if ($ menuItem ->haveChildren ()) {
206
+ $ firstChildrenItem = $ menuItem ->getChildren ()->first ();
207
+
208
+ $ menuItem ->setRoute ($ firstChildrenItem ->getRoute ());
209
+
210
+ $ this ->removeChildrenUnauthorizedMenuItem ($ firstChildrenItem );
211
+ }
212
+ }
188
213
}
You can’t perform that action at this time.
0 commit comments