Skip to content

Commit

Permalink
IBX-8534: Added relationList helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Oct 25, 2024
1 parent e5dcff1 commit 0bb1f71
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bundle/Core/Resources/config/helpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ services:
Ibexa\Bundle\Core\SiteAccess\Config\IOConfigResolver:
arguments:
$complexConfigProcessor: '@Ibexa\Bundle\Core\SiteAccess\Config\ComplexConfigProcessor'

Ibexa\Core\Helper\RelationListHelper:
arguments:
$contentService: '@ibexa.api.service.content'
45 changes: 45 additions & 0 deletions src/lib/Helper/RelationListHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Core\Helper;

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\Values\Content\VersionInfo;

final class RelationListHelper
{
public function __construct(
private readonly ContentService $contentService
) {
}

/**
* @return \Ibexa\Core\Repository\Values\Content\Relation[]
*/
public function getRelations(VersionInfo $versionInfo): array
{
$relationListIterator = new BatchIterator(
new RelationListIteratorAdapter(
$this->contentService,
$versionInfo
)
);

$relations = [];
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\RelationList\RelationListItemInterface $relationListItem */
foreach ($relationListIterator as $relationListItem) {
if ($relationListItem->hasRelation()) {
$relations[] = $relationListItem->getRelation();
}
}

return $relations;

Check failure on line 43 in src/lib/Helper/RelationListHelper.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.3)

Method Ibexa\Core\Helper\RelationListHelper::getRelations() should return array<Ibexa\Core\Repository\Values\Content\Relation> but returns array<int<0, max>, Ibexa\Contracts\Core\Repository\Values\Content\Relation|null>.
}
}

0 comments on commit 0bb1f71

Please sign in to comment.