Skip to content

Commit ec3df42

Browse files
committed
ContentService::loadRelations → ContentService::loadRelationList (#2544)
loadRelations is deprecated in 4.5, and removed in 5.0 --------- Co-authored-by: Marek Nocoń <[email protected]> (cherry picked from commit e68a80c)
1 parent d3ff58a commit ec3df42

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5353
$user = $this->userService->loadUserByLogin('admin');
5454
$this->permissionResolver->setCurrentUserReference($user);
5555

56-
$contentId = $input->getArgument('contentId');
56+
$contentId = (int) $input->getArgument('contentId');
5757

5858
// Metadata
5959
$contentInfo = $this->contentService->loadContentInfo($contentId);
@@ -99,10 +99,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9999

100100
// Relations
101101
$versionInfo = $this->contentService->loadVersionInfo($contentInfo);
102-
$relations = $this->contentService->loadRelations($versionInfo);
103-
foreach ($relations as $relation) {
104-
$name = $relation->destinationContentInfo->name;
105-
$output->writeln('Relation to content ' . $name);
102+
$relationCount = $this->contentService->countRelations($versionInfo);
103+
$relationList = $this->contentService->loadRelationList($versionInfo, 0, $relationCount);
104+
foreach ($relationList as $relationListItem) {
105+
$name = $relationListItem->hasRelation() ? $relationListItem->getRelation()->destinationContentInfo->name : '(Unauthorized)';
106+
$output->writeln("Relation to content '$name'");
106107
}
107108

108109
// Owner

code_samples/front/embed_content/src/Controller/RelationController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public function showContentAction(View $view, $locationId): View
2525
$location = $this->locationService->loadLocation($locationId);
2626
$contentInfo = $location->getContentInfo();
2727
$versionInfo = $this->contentService->loadVersionInfo($contentInfo);
28-
$relations = $this->contentService->loadRelations($versionInfo);
28+
$relationList = $this->contentService->loadRelationList($versionInfo);
2929

3030
$items = [];
3131

32-
foreach ($relations as $relation) {
33-
if (in_array($relation->getDestinationContentInfo()->getContentType()->identifier, $acceptedContentTypes)) {
34-
$items[] = $this->contentService->loadContentByContentInfo($relation->getDestinationContentInfo());
32+
foreach ($relationList as $relationListItem) {
33+
if ($relationListItem->hasRelation() && in_array($relationListItem->getRelation()->getDestinationContentInfo()->getContentType()->identifier, $acceptedContentTypes)) {
34+
$items[] = $this->contentService->loadContentByContentInfo($relationListItem->getRelation()->getDestinationContentInfo());
3535
}
3636
}
3737

docs/content_management/content_api/browsing_content.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ to get only versions of a specific status, e.g.:
103103

104104
Content Relations are versioned.
105105
To list Relations to and from your content,
106-
you need to pass a `VersionInfo` object to the [`ContentService::loadRelations`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadRelations) method.
106+
you need to pass a `VersionInfo` object to the [`ContentService::loadRelationList`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadRelationList) method. This method loads only the specified subset of relations to improve performance and was created with pagination in mind.
107107
You can get the current version's `VersionInfo` using [`ContentService::loadVersionInfo`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadVersionInfo).
108108

109109
``` php
110-
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 100, 106) =]]
110+
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 100, 107) =]]
111111
```
112112

113113
You can also specify the version number as the second argument to get Relations for a specific version:
@@ -116,7 +116,8 @@ You can also specify the version number as the second argument to get Relations
116116
$versionInfo = $this->contentService->loadVersionInfo($contentInfo, 2);
117117
```
118118

119-
`loadRelations` provides an array of [`Relation`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Relation.html) objects.
119+
`loadRelationList` provides an iterable [`RelationList`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-RelationList.html) object
120+
listing [`Relation`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Relation.html) objects.
120121
`Relation` has two main properties: `destinationContentInfo`, and `sourceContentInfo`.
121122
It also holds the [relation type](content_relations.md),
122123
and the optional Field this relation is made with.
@@ -126,7 +127,7 @@ and the optional Field this relation is made with.
126127
You can use the `getOwner` method of the `ContentInfo` object to load the content item's owner as a `User` value object.
127128

128129
``` php
129-
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 108, 109) =]]
130+
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 109, 110) =]]
130131
```
131132

132133
To get the creator of the current version and not the content item's owner,
@@ -139,7 +140,7 @@ the [`getSection`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-C
139140
of the ContentInfo object:
140141

141142
``` php
142-
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 111, 112) =]]
143+
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 112, 113) =]]
143144
```
144145

145146
!!! note
@@ -155,7 +156,7 @@ You need to provide it with the Object state group.
155156
All Object state groups can be retrieved through [`loadObjectStateGroups`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ObjectStateService.html#method_loadObjectStateGroups).
156157

157158
``` php
158-
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 114, 119) =]]
159+
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 115, 120) =]]
159160
```
160161

161162
## Viewing content with Fields

tools/code_samples/code_samples_usage_diff2html.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
continue;
3434
}
3535
$statusChar = strlen($diffLine) ? $diffLine[0] : '';
36-
$realLine = $str = substr($diffLine, 1);
36+
$realLine = str_replace(['<', '>'], ['&lt;', '&gt;'], substr($diffLine, 1));
3737
if ($previousStatusChar !== $statusChar) {
3838
switch ("$previousStatusChar$statusChar") {
3939
case ' +':

0 commit comments

Comments
 (0)