Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentService::loadRelations → ContentService::loadRelationList #2544

Merged
merged 8 commits into from
Nov 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

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

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

// Relations
$versionInfo = $this->contentService->loadVersionInfo($contentInfo);
$relations = $this->contentService->loadRelations($versionInfo);
foreach ($relations as $relation) {
$name = $relation->destinationContentInfo->name;
$output->writeln('Relation to content ' . $name);
$relationCount = $this->contentService->countRelations($versionInfo);
adriendupuis marked this conversation as resolved.
Show resolved Hide resolved
$relationList = $this->contentService->loadRelationList($versionInfo, 0, $relationCount);
foreach ($relationList as $relationListItem) {
$name = $relationListItem->getRelation()->destinationContentInfo->name;
adriendupuis marked this conversation as resolved.
Show resolved Hide resolved
$output->writeln("Relation to content '$name'");
}

// Owner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function showContentAction(View $view, $locationId): View
$location = $this->locationService->loadLocation($locationId);
$contentInfo = $location->getContentInfo();
$versionInfo = $this->contentService->loadVersionInfo($contentInfo);
$relations = $this->contentService->loadRelations($versionInfo);
$relationList = $this->contentService->loadRelationList($versionInfo);

$items = [];

foreach ($relations as $relation) {
if (in_array($relation->getDestinationContentInfo()->getContentType()->identifier, $acceptedContentTypes)) {
$items[] = $this->contentService->loadContentByContentInfo($relation->getDestinationContentInfo());
foreach ($relationList as $relationListItem) {
if (in_array($relationListItem->getRelation()->getDestinationContentInfo()->getContentType()->identifier, $acceptedContentTypes)) {
adriendupuis marked this conversation as resolved.
Show resolved Hide resolved
$items[] = $this->contentService->loadContentByContentInfo($relationListItem->getRelation()->getDestinationContentInfo());
}
}

Expand Down
13 changes: 7 additions & 6 deletions docs/content_management/content_api/browsing_content.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@

Content Relations are versioned.
To list Relations to and from your content,
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.
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.

Check failure on line 106 in docs/content_management/content_api/browsing_content.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/content_management/content_api/browsing_content.md#L106

[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'
Raw output
{"message": "[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'", "location": {"path": "docs/content_management/content_api/browsing_content.md", "range": {"start": {"line": 106, "column": 129}}}, "severity": "ERROR"}
adriendupuis marked this conversation as resolved.
Show resolved Hide resolved
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).

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 100, 106) =]]
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 100, 107) =]]
```

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

`loadRelations` provides an array of [`Relation`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Relation.html) objects.
`loadRelationList` provides an iterable [`RelationList`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-RelationList.html) object

Check failure on line 119 in docs/content_management/content_api/browsing_content.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/content_management/content_api/browsing_content.md#L119

[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'
Raw output
{"message": "[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'", "location": {"path": "docs/content_management/content_api/browsing_content.md", "range": {"start": {"line": 119, "column": 102}}}, "severity": "ERROR"}
listing [`Relation`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Relation.html) objects.

Check failure on line 120 in docs/content_management/content_api/browsing_content.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/content_management/content_api/browsing_content.md#L120

[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'
Raw output
{"message": "[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'", "location": {"path": "docs/content_management/content_api/browsing_content.md", "range": {"start": {"line": 120, "column": 66}}}, "severity": "ERROR"}
`Relation` has two main properties: `destinationContentInfo`, and `sourceContentInfo`.
It also holds the [relation type](content_relations.md),
and the optional Field this relation is made with.
Expand All @@ -126,7 +127,7 @@
You can use the `getOwner` method of the `ContentInfo` object to load the content item's owner as a `User` value object.

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 108, 109) =]]
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 109, 110) =]]
```

To get the creator of the current version and not the content item's owner,
Expand All @@ -139,7 +140,7 @@
of the ContentInfo object:

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 111, 112) =]]
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 112, 113) =]]
```

!!! note
Expand All @@ -155,7 +156,7 @@
All Object state groups can be retrieved through [`loadObjectStateGroups`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ObjectStateService.html#method_loadObjectStateGroups).

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 114, 119) =]]
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 115, 120) =]]
```

## Viewing content with Fields
Expand Down
2 changes: 1 addition & 1 deletion tools/code_samples/code_samples_usage_diff2html.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
continue;
}
$statusChar = strlen($diffLine) ? $diffLine[0] : '';
$realLine = $str = substr($diffLine, 1);
$realLine = str_replace(['<', '>'], ['&lt;', '&gt;'], substr($diffLine, 1));
if ($previousStatusChar !== $statusChar) {
switch ("$previousStatusChar$statusChar") {
case ' +':
Expand Down
Loading