Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
04aebc3
ViewContentMetaDataCommand.php: Fix arg type
adriendupuis Nov 15, 2024
5bb1f2d
browsing_content.md: Use loadRelationList instead of loadRelations
adriendupuis Nov 15, 2024
da094da
RelationController.php: Use loadRelationList instead of loadRelations
adriendupuis Nov 15, 2024
cfa1c89
code_samples_usage_diff2html.php: escape < and >
adriendupuis Nov 15, 2024
aba03c3
Update code_samples/api/public_php_api/src/Command/ViewContentMetaDat…
adriendupuis Nov 20, 2024
540f4fe
ViewContentMetaDataCommand.php: Use RelationListIteratorAdapter
adriendupuis Nov 20, 2024
1660c18
browsing_content.md: Use RelationListIteratorAdapter
adriendupuis Nov 20, 2024
3ad69f9
PHP API Ref: RelationListIteratorAdapter
adriendupuis Nov 20, 2024
967d0a1
Merge branch 'master' into 5.0-relationlistiterator
adriendupuis Nov 27, 2024
ee23889
Merge branch '5.0' into 5.0-relationlistiterator
adriendupuis Jun 6, 2025
82f3b6e
browsing_content.md: Fix include_file indexes after merge
adriendupuis Jun 6, 2025
d4b3637
RelationController: use RelationListIteratorAdapter
adriendupuis Jun 6, 2025
4a7cf16
embed_content.md: Match RelationController
adriendupuis Jun 6, 2025
fe4b07c
Merge branch '5.0' into 5.0-relationlistiterator
adriendupuis Jun 10, 2025
6bfd8f2
Merge branch '5.0' into 5.0-relationlistiterator
adriendupuis Jul 22, 2025
5ff4dee
Merge branch '5.0' into 5.0-relationlistiterator
adriendupuis Jul 22, 2025
d025c0c
browsing_content.md: Reword method VS object
adriendupuis Jul 22, 2025
c3599fe
Merge branch '5.0' into 5.0-relationlistiterator
adriendupuis Aug 25, 2026
5d89898
search_api.md + RelationListIteratorAdapter
adriendupuis Aug 25, 2026
304c554
search_api.md: Enh. Adapter|Method table
adriendupuis Aug 25, 2026
63f5702
search_api.md: Enh. Adapter|Method table
adriendupuis Aug 25, 2026
19daab9
browsing_content.md: Fix an code sample include
adriendupuis Aug 25, 2026
a60e5e0
Merge branch '5.0' into 5.0-relationlistiterator
adriendupuis Aug 25, 2026
5edf362
controllers.md: Fix RelationController include
adriendupuis Aug 25, 2026
2e7142d
embed_content.md: HL less lines
adriendupuis Aug 25, 2026
90f76c1
Update docs/content_management/content_api/browsing_content.md
adriendupuis Aug 25, 2026
b324feb
browsing_content.md: Fix ContentInfo line nums
adriendupuis Aug 25, 2026
ca53505
Update docs/content_management/content_api/browsing_content.md
adriendupuis Aug 25, 2026
65665f4
Update docs/content_management/content_api/browsing_content.md
adriendupuis Aug 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Command;

use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\Iterator\BatchIterator;
use Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\RelationListIteratorAdapter;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\ObjectStateService;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
Expand Down Expand Up @@ -91,9 +93,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Relations
$versionInfo = $this->contentService->loadVersionInfo($contentInfo);
$relationCount = $this->contentService->countRelations($versionInfo);
Comment thread
adriendupuis marked this conversation as resolved.
$relationList = $this->contentService->loadRelationList($versionInfo, 0, $relationCount);
foreach ($relationList as $relationListItem) {
$relationListIterator = new BatchIterator(
new RelationListIteratorAdapter(
$this->contentService,
$versionInfo
)
);
foreach ($relationListIterator as $relationListItem) {
$name = $relationListItem->hasRelation() ? $relationListItem->getRelation()->destinationContentInfo->name : '(Unauthorized)';
$output->writeln("Relation to content '$name'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Controller;

use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\Iterator\BatchIterator;
use Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\RelationListIteratorAdapter;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Core\MVC\Symfony\View\View;

Expand All @@ -21,11 +23,16 @@ public function showContentAction(View $view, $locationId): View
$location = $this->locationService->loadLocation($locationId);
$contentInfo = $location->getContentInfo();
$versionInfo = $this->contentService->loadVersionInfo($contentInfo);
$relationList = $this->contentService->loadRelationList($versionInfo);
$relationListIterator = new BatchIterator(
new RelationListIteratorAdapter(
$this->contentService,
$versionInfo
)
);

$items = [];

foreach ($relationList as $relationListItem) {
foreach ($relationListIterator as $relationListItem) {
if ($relationListItem->hasRelation() && in_array($relationListItem->getRelation()->getDestinationContentInfo()->getContentType()->identifier, $acceptedContentTypes)) {
$items[] = $this->contentService->loadContentByContentInfo($relationListItem->getRelation()->getDestinationContentInfo());
}
Expand Down
69 changes: 40 additions & 29 deletions docs/content_management/content_api/browsing_content.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@

You can also use it to request other content-related value objects from various services:

``` php hl_lines="14"
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 0, 5) =]]
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 21, 23) =]]
// ...

[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 42, 44) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 50, 58) =]]
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 113, 116) =]]
``` php hl_lines="13"
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 1, 5) =]]

// …
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 24, 25) =]]
// …
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 45, 46) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 53, 60) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 119) =]]
```

`ContentInfo` is loaded from the [`ContentService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html) (line 8).
`ContentInfo` is loaded from the [`ContentService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html) (line 13).

Check notice on line 39 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#L39

[Ibexa.Passive] Try to avoid passive tense, when possible.
Raw output
{"message": "[Ibexa.Passive] Try to avoid passive tense, when possible.", "location": {"path": "docs/content_management/content_api/browsing_content.md", "range": {"start": {"line": 39, "column": 15}}}, "severity": "INFO"}
It provides you with basic content metadata such as modification and publication dates or main language code.

!!! note "Retrieving content information in a controller"
Expand All @@ -46,7 +48,8 @@
To get the locations of a content item you need to make use of the [`LocationService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html):

``` php
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 56, 61, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 63, 66, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 69, 69, remove_indent=True) =]]
```

[`LocationService::loadLocations`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_loadLocations) uses `ContentInfo` to get all the locations of a content item.
Expand All @@ -60,29 +63,30 @@
[`URLAliasService::reverseLookup`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-URLAliasService.html#method_reverseLookup) gets the location's main [URL alias](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-URLAlias.html):

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 73, 76) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 77, 80) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 63, 65, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 67, 69, remove_indent=True) =]]
```

### Content type

You can retrieve the content type of a content item through the [`getContentType`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentInfo.html#method_getContentType) method of the ContentInfo object:

``` php
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 70, 71, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 72, 73, remove_indent=True) =]]
```

### Versions

To iterate over the versions of a content item, use the [`ContentService::loadVersions`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadVersions) method, which returns an array of `VersionInfo` value objects.

``` php
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 74, 79, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 76, 81, remove_indent=True) =]]
```

You can additionally provide the `loadVersions` method with the version status to get only versions of a specific status, for example:

``` php
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 81, 81, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 83, 83, remove_indent=True) =]]
```

!!! note
Expand All @@ -93,12 +97,18 @@
### Relations

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

- pass a `VersionInfo` object to the [`ContentService::loadRelationList` method](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadRelationList) which returns a slice of the relation list thanks to pagination arguments
- use the [`RelationListIteratorAdapter`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Iterator-BatchIteratorAdapter-RelationListIteratorAdapter.html)
within a [`BatchIterator`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Iterator-BatchIterator.html) which allow traversing the whole relation list

See [Processing large result sets](search_api.md#process-large-result-sets) for more information about the `BatchIterator`.

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_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 93, 99, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 95, 105, remove_indent=True) =]]
```

You can also specify the version number as the second argument to get Relations for a specific version:
Expand All @@ -121,7 +131,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_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 102, 102, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 108, 108, remove_indent=True) =]]
```

To get the creator of the current version and not the content item's owner, you need to use the `creatorId` property from the current version's `VersionInfo` object.
Expand All @@ -131,7 +141,7 @@
You can find the section to which a content item belongs through the [`getSection`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentInfo.html#method_getSection) method of the ContentInfo object:

``` php
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 105, 105, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 111, 111, remove_indent=True) =]]
```

!!! note
Expand All @@ -146,26 +156,27 @@
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_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 108, 112, remove_indent=True) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 114, 118, remove_indent=True) =]]
Comment thread
adriendupuis marked this conversation as resolved.
```

## Viewing content with fields
## Viewing field definitions of content types

To retrieve the fields of the selected content item, you can use the following command:
To retrieve the content type's field definitions of a selected content item, you can use the following command:

``` php hl_lines="17-18 20-27"
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 0, 7) =]]
// ...
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 17, 19) =]]
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 35, 54) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 1, 7) =]]

// …
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 18, 19) =]]
// …
[[= include_code('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 36) =]]
```

Line 9 shows how [`ContentService::loadContent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadContent) loads the content item provided to the command.
Line 10 makes use of the [`ContentTypeService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentTypeService.html) to retrieve the content type of the requested item.
Line 17 shows how [`ContentService::loadContent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadContent) loads the content item provided to the command.
Line 18 makes use of the [`ContentTypeService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentTypeService.html) to retrieve the content type of the requested item.

Lines 12-19 iterate over fields defined by the content type.
For each field they print out its identifier, and then using [`FieldTypeService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-FieldTypeService.html) retrieve the field's value and print it out to the console.
Lines 20-27 iterate over fields defined by the content type.
For each field definition they print out its identifier, and then using [`FieldTypeService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-FieldTypeService.html) retrieve the field definition's value and print it out to the console.

Check notice on line 179 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#L179

[Ibexa.ByUsing] Prefer 'by using' or 'with' to plain 'using'.
Raw output
{"message": "[Ibexa.ByUsing] Prefer 'by using' or 'with' to plain 'using'.", "location": {"path": "docs/content_management/content_api/browsing_content.md", "range": {"start": {"line": 179, "column": 62}}}, "severity": "INFO"}

## Viewing content in different languages

Expand Down
Loading
Loading