Skip to content

Commit b148853

Browse files
authored
IBX-1507: Provided additional arguments for Location Visitor (#86)
* IBX-1507: Provided additional arguments for Location Visitor * IBX-1507: Updated service definition * IBX-1507: Provided functional test * IBX-1507: CS remarks * IBX-1507: Rollback stdClass usage
1 parent 7d0d264 commit b148853

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

src/bundle/Resources/config/value_object_visitors.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,9 @@ services:
598598
class: "%ezpublish_rest.output.value_object_visitor.Location.class%"
599599
tags:
600600
- { name: ezpublish_rest.output.value_object_visitor, type: eZ\Publish\API\Repository\Values\Content\Location }
601-
arguments: ["@ezpublish.api.service.location"]
601+
arguments:
602+
$locationService: '@ezpublish.api.service.location'
603+
$contentService: '@ezpublish.api.service.content'
602604

603605
ezpublish_rest.output.value_object_visitor.LocationList:
604606
parent: ezpublish_rest.output.value_object_visitor.base

src/lib/Server/Output/ValueObjectVisitor/Location.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77
namespace EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor;
88

9+
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
910
use eZ\Publish\API\Repository\LocationService;
11+
use eZ\Publish\API\Repository\ContentService;
1012
use EzSystems\EzPlatformRest\Output\ValueObjectVisitor;
1113
use EzSystems\EzPlatformRest\Output\Generator;
1214
use EzSystems\EzPlatformRest\Output\Visitor;
@@ -18,14 +20,16 @@
1820
*/
1921
class Location extends ValueObjectVisitor
2022
{
21-
/**
22-
* @var \eZ\Publish\API\Repository\LocationService
23-
*/
23+
/** @var \eZ\Publish\API\Repository\LocationService */
2424
private $locationService;
2525

26-
public function __construct(LocationService $locationService)
26+
/** @var \eZ\Publish\API\Repository\ContentService */
27+
private $contentService;
28+
29+
public function __construct(LocationService $locationService, ContentService $contentService)
2730
{
2831
$this->locationService = $locationService;
32+
$this->contentService = $contentService;
2933
}
3034

3135
/**
@@ -147,7 +151,27 @@ protected function visitLocationAttributes(Visitor $visitor, Generator $generato
147151
)
148152
);
149153
$generator->endAttribute('href');
150-
$visitor->visitValueObject(new RestContentValue($location->contentInfo));
154+
155+
$content = $location->getContent();
156+
$contentInfo = $location->contentInfo;
157+
158+
try {
159+
$mainLocation = $contentInfo->mainLocationId === $location->id
160+
? $location
161+
: $this->locationService->loadLocation($contentInfo->mainLocationId);
162+
} catch (UnauthorizedException $e) {
163+
$mainLocation = null;
164+
}
165+
166+
$visitor->visitValueObject(new RestContentValue(
167+
$contentInfo,
168+
$mainLocation,
169+
$content,
170+
$content->getContentType(),
171+
$this->contentService->loadRelations($content->getVersionInfo())
172+
)
173+
);
174+
151175
$generator->endObjectElement('ContentInfo');
152176
}
153177
}

tests/bundle/Functional/SearchView/SearchViewTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,40 @@ public function testSimpleXmlContentQuery(string $xmlQueryBody, int $expectedCou
7474
self::assertEquals($expectedCount, $this->getQueryResultsCount('xml', $body));
7575
}
7676

77+
public function testLocationsByIdQueryContainsCurrentVersionObject(): void
78+
{
79+
$body = <<<JSON
80+
{
81+
"ViewInput": {
82+
"identifier": "locations-by-id",
83+
"public": "false",
84+
"LocationQuery": {
85+
"Filter": {
86+
"LocationIdCriterion": "2"
87+
},
88+
"limit": "10",
89+
"offset": "0"
90+
}
91+
}
92+
}
93+
JSON;
94+
95+
$request = $this->createHttpRequest(
96+
'POST',
97+
'/api/ezp/v2/views',
98+
'ViewInput+json; version=1.1',
99+
'View+json',
100+
$body
101+
);
102+
103+
$response = $this->sendHttpRequest($request);
104+
$jsonResponse = json_decode($response->getBody()->getContents());
105+
106+
$content = $jsonResponse->View->Result->searchHits->searchHit[0]->value->Location->ContentInfo->Content;
107+
108+
self::assertIsObject($content->CurrentVersion->Version);
109+
}
110+
77111
/**
78112
* Covers POST with LocationQuery Logic on /api/ezp/v2/views using payload in the JSON format.
79113
*

0 commit comments

Comments
 (0)