99namespace Ibexa \AdminUi \Menu \Voter ;
1010
1111use Ibexa \Core \MVC \Symfony \View \ContentView ;
12+ use Ibexa \Core \Repository \Values \Content \Location ;
1213use Knp \Menu \ItemInterface ;
1314use Knp \Menu \Matcher \Voter \VoterInterface ;
1415use Symfony \Component \HttpFoundation \RequestStack ;
@@ -26,20 +27,24 @@ public function __construct(RequestStack $requestStack)
2627
2728 public function matchItem (ItemInterface $ item ): ?bool
2829 {
29- $ routes = $ item ->getExtra ('routes ' , []);
30-
31- foreach ($ routes as $ route ) {
32- if (isset ($ route ['route ' ]) && $ route ['route ' ] === self ::CONTENT_VIEW_ROUTE_NAME ) {
33- $ request = $ this ->requestStack ->getCurrentRequest ();
34- $ contentView = $ request ->attributes ->get ('view ' );
35- $ locationId = $ route ['parameters ' ]['locationId ' ];
36-
37- if ($ contentView instanceof ContentView) {
38- $ location = $ contentView ->getLocation ();
39- if ($ location !== null && in_array ($ locationId , $ location ->path ?? [$ location ->id ])) {
40- return true ;
41- }
42- }
30+ foreach ($ item ->getExtra ('routes ' , []) as $ route ) {
31+ $ routeName = $ route ['route ' ] ?? null ;
32+ $ locationId = isset ($ route ['parameters ' ]['locationId ' ]) ? (int )$ route ['parameters ' ]['locationId ' ] : null ;
33+
34+ if ($ routeName !== self ::CONTENT_VIEW_ROUTE_NAME || $ locationId === null ) {
35+ continue ;
36+ }
37+
38+ $ request = $ this ->requestStack ->getCurrentRequest ();
39+ $ contentView = $ request ? $ request ->attributes ->get ('view ' ) : null ;
40+ $ location = $ contentView instanceof ContentView ? $ contentView ->getLocation () : null ;
41+
42+ if (!$ location instanceof Location) {
43+ continue ;
44+ }
45+
46+ if (in_array ($ locationId , array_map ('intval ' , $ location ->getPath ()), true )) {
47+ return true ;
4348 }
4449 }
4550
0 commit comments