Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions bundle/Resources/config/services/page/visitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ services:
netgen.openapi_ibexa.page.output.visitor.layouts.block:
class: Netgen\OpenApiIbexa\Page\Output\Visitor\Layouts\BlockVisitor
arguments:
- '@Ibexa\HttpCache\Handler\TagHandler'
- '@netgen_layouts.collection.result.pagerfanta.factory'
- '@ibexa.config.resolver'
tags:
Expand Down
19 changes: 18 additions & 1 deletion lib/Page/Output/Visitor/Layouts/BlockVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Generator;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Ibexa\HttpCache\Handler\TagHandler;
use Netgen\IbexaSiteApi\API\Values\Content;
use Netgen\IbexaSiteApi\API\Values\Location;
use Netgen\Layouts\API\Values\Block\Block;
Expand All @@ -18,12 +19,15 @@
use Netgen\OpenApiIbexa\Page\Output\VisitorInterface;
use ReflectionClass;

use function is_int;

/**
* @implements \Netgen\OpenApiIbexa\Page\Output\VisitorInterface<\Netgen\Layouts\API\Values\Block\Block>
*/
final class BlockVisitor implements VisitorInterface
{
public function __construct(
private TagHandler $tagHandler,
private PagerFactory $pagerFactory,
private ConfigResolverInterface $configResolver,
) {}
Expand All @@ -48,11 +52,24 @@ public function visit(object $value, OutputVisitor $outputVisitor, array $parame
];

if ($value->hasCollection('default')) {
/** @var \Netgen\Layouts\API\Values\Collection\Collection $collection */
$collection = $value->getCollection('default');

/** @var \Netgen\Layouts\Collection\Result\ResultSet $resultSet */
$resultSet = $this->pagerFactory
->getPager($value->getCollection('default'), 1)
->getPager($collection, 1)
->getCurrentPageResults();

$query = $collection->getQuery();

$parentLocation = $query?->hasParameter('parent_location_id') === true
? $query->getParameter('parent_location_id')->getValue()
: null;

if (is_int($parentLocation)) {
$this->tagHandler->addLocationTags([$parentLocation]);
}

$properties['items'] = [...$this->visitItems($resultSet, $outputVisitor)];
}

Expand Down
Loading