Skip to content

Commit 21cf2e6

Browse files
committed
IBX-6554: Enhanced null safety and refactored location ID checks in LocationVoter
1 parent 451b04a commit 21cf2e6

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11496,12 +11496,6 @@ parameters:
1149611496
count: 1
1149711497
path: src/lib/Menu/UserSetting/UserSettingUpdateRightSidebarBuilder.php
1149811498

11499-
-
11500-
message: '#^Cannot access property \$attributes on Symfony\\Component\\HttpFoundation\\Request\|null\.$#'
11501-
identifier: property.nonObject
11502-
count: 1
11503-
path: src/lib/Menu/Voter/LocationVoter.php
11504-
1150511499
-
1150611500
message: '#^Call to an undefined method Symfony\\Component\\HttpFoundation\\Session\\SessionInterface\:\:getFlashBag\(\)\.$#'
1150711501
identifier: method.notFound

src/lib/Menu/Voter/LocationVoter.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Ibexa\AdminUi\Menu\Voter;
1010

1111
use Ibexa\Core\MVC\Symfony\View\ContentView;
12+
use Ibexa\Core\Repository\Values\Content\Location;
1213
use Knp\Menu\ItemInterface;
1314
use Knp\Menu\Matcher\Voter\VoterInterface;
1415
use 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

Comments
 (0)