Skip to content

Commit 60095b6

Browse files
committed
Merge branch '4.4' into main
2 parents f38802c + 2faca6e commit 60095b6

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/lib/FieldTypeProcessor/BaseRelationProcessor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
namespace Ibexa\Rest\FieldTypeProcessor;
88

9+
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
10+
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException;
911
use Ibexa\Contracts\Core\Repository\LocationService;
1012
use Ibexa\Contracts\Rest\FieldTypeProcessor;
1113
use Ibexa\Core\FieldType\Relation\Type;
@@ -64,8 +66,14 @@ public function mapToContentHref($contentId)
6466
*/
6567
public function mapToLocationHref($locationId)
6668
{
69+
try {
70+
$location = $this->locationService->loadLocation($locationId);
71+
} catch (UnauthorizedException | NotFoundException $e) {
72+
return '';
73+
}
74+
6775
return $this->router->generate('ibexa.rest.load_location', [
68-
'locationPath' => implode('/', $this->locationService->loadLocation($locationId)->path),
76+
'locationPath' => implode('/', $location->path),
6977
]);
7078
}
7179

tests/lib/FieldTypeProcessor/RelationProcessorTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Ibexa\Tests\Rest\FieldTypeProcessor;
88

99
use Ibexa\Contracts\Core\Repository\LocationService;
10+
use Ibexa\Core\Base\Exceptions\NotFoundException;
1011
use Ibexa\Core\Repository\Values\Content\Location;
1112
use Ibexa\Rest\FieldTypeProcessor\RelationProcessor;
1213
use PHPUnit\Framework\TestCase;
@@ -127,6 +128,33 @@ public function testPostProcessFieldValueHashNullValue()
127128
$this->assertArrayNotHasKey('destinationContentHref', $hash);
128129
}
129130

131+
public function testPostProcessFieldValueHashNotAccessibleLocation(): void
132+
{
133+
$processor = $this->getProcessor();
134+
135+
$serviceLocationMock = $this->createMock(LocationService::class);
136+
$processor->setLocationService($serviceLocationMock);
137+
138+
$serviceLocationMock
139+
->method('loadLocation')
140+
->with('-1')
141+
->willThrowException(new NotFoundException('', ''));
142+
143+
$routerMock = $this->createMock(RouterInterface::class);
144+
$processor->setRouter($routerMock);
145+
146+
$routerMock
147+
->expects(self::never())
148+
->method('generate');
149+
150+
$hash = $processor->postProcessFieldSettingsHash(['selectionRoot' => -1]);
151+
152+
self::assertSame([
153+
'selectionRoot' => -1,
154+
'selectionRootHref' => '',
155+
], $hash);
156+
}
157+
130158
/**
131159
* @return \Ibexa\Rest\FieldTypeProcessor\RelationProcessor
132160
*/

0 commit comments

Comments
 (0)