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 30, 2024
1 parent 13bd157 commit b9f0825
Show file tree
Hide file tree
Showing 2 changed files with 51 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'
47 changes: 47 additions & 0 deletions src/lib/Helper/RelationListHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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()) {
/** @var \Ibexa\Core\Repository\Values\Content\Relation $relation */
$relation = $relationListItem->getRelation();
$relations[] = $relation;
}
}

return $relations;
}
}

0 comments on commit b9f0825

Please sign in to comment.