From 04aebc3352f871b9b618098ad6fc0bfbc2a8e747 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:25:16 +0100 Subject: [PATCH 1/8] ViewContentMetaDataCommand.php: Fix arg type Fix "Argument #1 ($contentId) must be of type int, string given" --- .../public_php_api/src/Command/ViewContentMetaDataCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php index 2d3cdf92d5..769a973779 100644 --- a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php +++ b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php @@ -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); From 5bb1f2d0f0f5f5af882264b182f720fbc81475cb Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:06:23 +0100 Subject: [PATCH 2/8] browsing_content.md: Use loadRelationList instead of loadRelations loadRelations is deprecated in 4.5, and removed in 5.0 Fix "Call to an undefined method Ibexa\Contracts\Core\Repository\ContentService::loadRelations()." on PHPStan + 5.0 --- .../src/Command/ViewContentMetaDataCommand.php | 9 +++++---- .../content_api/browsing_content.md | 13 +++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php index 769a973779..c9c5ed1490 100644 --- a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php +++ b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php @@ -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); + $relationList = $this->contentService->loadRelationList($versionInfo, 0, $relationCount); + foreach ($relationList as $relationListItem) { + $name = $relationListItem->getRelation()->destinationContentInfo->name; + $output->writeln("Relation to content '$name'"); } // Owner diff --git a/docs/content_management/content_api/browsing_content.md b/docs/content_management/content_api/browsing_content.md index 5fa8eecf96..a8b34725a6 100644 --- a/docs/content_management/content_api/browsing_content.md +++ b/docs/content_management/content_api/browsing_content.md @@ -103,11 +103,11 @@ to get only versions of a specific status, e.g.: 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. 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: @@ -116,7 +116,8 @@ You can also specify the version number as the second argument to get Relations $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 +listing [`Relation`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Relation.html) objects. `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. @@ -126,7 +127,7 @@ and the optional Field this relation is made with. 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, @@ -139,7 +140,7 @@ the [`getSection`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-C 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 @@ -155,7 +156,7 @@ You need to provide it with the Object state group. 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 From da094da4c3aec4c9fe85cbf9e7dc2a56d679bd47 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:25:33 +0100 Subject: [PATCH 3/8] RelationController.php: Use loadRelationList instead of loadRelations loadRelations is deprecated in 4.5, and removed in 5.0 Fix "Call to an undefined method Ibexa\Contracts\Core\Repository\ContentService::loadRelations()." on PHPStan + 5.0 --- .../embed_content/src/Controller/RelationController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code_samples/front/embed_content/src/Controller/RelationController.php b/code_samples/front/embed_content/src/Controller/RelationController.php index 129a0369a3..2578231531 100644 --- a/code_samples/front/embed_content/src/Controller/RelationController.php +++ b/code_samples/front/embed_content/src/Controller/RelationController.php @@ -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)) { + $items[] = $this->contentService->loadContentByContentInfo($relationListItem->getRelation()->getDestinationContentInfo()); } } From cfa1c89aace3c1a635bc5baa42b50da3abf0747e Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:57:41 +0100 Subject: [PATCH 4/8] code_samples_usage_diff2html.php: escape < and > --- tools/code_samples/code_samples_usage_diff2html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/code_samples/code_samples_usage_diff2html.php b/tools/code_samples/code_samples_usage_diff2html.php index 965cd3f6ae..f15f6fe28c 100644 --- a/tools/code_samples/code_samples_usage_diff2html.php +++ b/tools/code_samples/code_samples_usage_diff2html.php @@ -33,7 +33,7 @@ continue; } $statusChar = strlen($diffLine) ? $diffLine[0] : ''; - $realLine = $str = substr($diffLine, 1); + $realLine = str_replace(['<', '>'], ['<', '>'], substr($diffLine, 1)); if ($previousStatusChar !== $statusChar) { switch ("$previousStatusChar$statusChar") { case ' +': From aba03c3aa4bd0f57ed1bda896d3cac4126e2bf26 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:50:54 +0100 Subject: [PATCH 5/8] Update code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php --- .../public_php_api/src/Command/ViewContentMetaDataCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php index c9c5ed1490..6037ae2515 100644 --- a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php +++ b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php @@ -102,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $relationCount = $this->contentService->countRelations($versionInfo); $relationList = $this->contentService->loadRelationList($versionInfo, 0, $relationCount); foreach ($relationList as $relationListItem) { - $name = $relationListItem->getRelation()->destinationContentInfo->name; + $name = $relationListItem->hasRelation() ? $relationListItem->getRelation()->destinationContentInfo->name : '(Unauthorized)'; $output->writeln("Relation to content '$name'"); } From 540f4fed681bd47ece82faae8a64832abb11f628 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:22:46 +0100 Subject: [PATCH 6/8] ViewContentMetaDataCommand.php: Use RelationListIteratorAdapter --- .../src/Command/ViewContentMetaDataCommand.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php index 6037ae2515..de0404822f 100644 --- a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php +++ b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php @@ -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; @@ -99,9 +101,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Relations $versionInfo = $this->contentService->loadVersionInfo($contentInfo); - $relationCount = $this->contentService->countRelations($versionInfo); - $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'"); } From 1660c18c0689c6909a2ef4ca505c4ebf56e79fe9 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:50:07 +0100 Subject: [PATCH 7/8] browsing_content.md: Use RelationListIteratorAdapter --- .../content_api/browsing_content.md | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/docs/content_management/content_api/browsing_content.md b/docs/content_management/content_api/browsing_content.md index a8b34725a6..d45efa9193 100644 --- a/docs/content_management/content_api/browsing_content.md +++ b/docs/content_management/content_api/browsing_content.md @@ -29,10 +29,10 @@ You can also use it to request other Content-related value objects from various ``` php hl_lines="9" // ... [[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 4, 5) =]] -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 16, 17) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 18, 19) =]] // ... -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 50, 52) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 58, 59) =]] -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 60, 66) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 52, 54) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 60, 61) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 62, 68) =]] ``` `ContentInfo` is loaded from the [`ContentService`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html) (line 9). @@ -49,7 +49,7 @@ It provides you with basic content metadata such as modification and publication 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_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 68, 72) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 70, 74) =]] ``` [`LocationService::loadLocations`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_loadLocations) @@ -66,7 +66,7 @@ additionally enables you to retrieve the human-readable [URL alias](url_manageme 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', 68, 71) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 72, 75) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 70, 73) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 74, 77) =]] ``` ### Content type @@ -75,7 +75,7 @@ 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_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 77, 79) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 79, 81) =]] ``` ### Versions @@ -84,14 +84,14 @@ 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_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 81, 87) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 83, 90) =]] ``` You can additionally provide the `loadVersions` method with the version status to get only versions of a specific status, e.g.: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 88, 89) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 90, 91) =]] ``` !!! note @@ -103,11 +103,12 @@ to get only versions of a specific status, e.g.: 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. +you can 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 which is paginated. +Or you can 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). 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, 107) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 102, 113) =]] ``` You can also specify the version number as the second argument to get Relations for a specific version: @@ -127,7 +128,7 @@ and the optional Field this relation is made with. 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', 109, 110) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 115, 116) =]] ``` To get the creator of the current version and not the content item's owner, @@ -140,7 +141,7 @@ the [`getSection`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-C of the ContentInfo object: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 112, 113) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 118, 119) =]] ``` !!! note @@ -156,7 +157,7 @@ You need to provide it with the Object state group. 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', 115, 120) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 121, 126) =]] ``` ## Viewing content with Fields From 3ad69f933d5a87d8f4f05881f53fecbdd360899f Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:13:24 +0100 Subject: [PATCH 8/8] PHP API Ref: RelationListIteratorAdapter --- ...orAdapter-RelationListIteratorAdapter.html | 36729 ++++++++++++++++ 1 file changed, 36729 insertions(+) create mode 100644 docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Iterator-BatchIteratorAdapter-RelationListIteratorAdapter.html diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Iterator-BatchIteratorAdapter-RelationListIteratorAdapter.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Iterator-BatchIteratorAdapter-RelationListIteratorAdapter.html new file mode 100644 index 0000000000..c6412afc74 --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Iterator-BatchIteratorAdapter-RelationListIteratorAdapter.html @@ -0,0 +1,36729 @@ + + + + + PHP API Reference + + + + + + + + + + + + + + +
Copied!
+ + + +
+ +
+ +
+
+
+ + +
+
+
+ + + +
+
+ + +
+

+ RelationListIteratorAdapter

+ +
+ RelationListIteratorAdapter.php + : + 18 + +
+ +
+ Implements + BatchIteratorAdapter
+ +
+ + + + + + + + + + + + + + + + +

+ Methods +

+ +
+

+ public__construct() + +

+
+ RelationListIteratorAdapter.php + : + 20 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public __construct(ContentService $contentService, VersionInfo $versionInfo[, RelationType|null $relationType = null ])
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $contentService + + ContentService + + - + + - +
+ $versionInfo + + VersionInfo + + - + + - +
+ $relationType + + RelationType|null + + null + + - +
+ +
+

+ publicfetch() + +

+
+ RelationListIteratorAdapter.php + : + 27 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public fetch(int $offset, int $limit) : Iterator
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $offset + + int + + - + + - +
+ $limit + + int + + - + + - +
+

Return values

+

Iterator

+ +
+
+
+ +
+
+
+ +
+
+
+
+
+
+ + + + + + + + + +