From 8ac96567e919e653f366fe90e942f247c5c988e7 Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Thu, 28 May 2026 07:13:42 +0200 Subject: [PATCH] PROSTSUPP-187 tag with parent location in block visitor using parent location id block collection parameter value --- .../config/services/page/visitors.yaml | 1 + .../Output/Visitor/Layouts/BlockVisitor.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bundle/Resources/config/services/page/visitors.yaml b/bundle/Resources/config/services/page/visitors.yaml index e790b64..f0a779e 100644 --- a/bundle/Resources/config/services/page/visitors.yaml +++ b/bundle/Resources/config/services/page/visitors.yaml @@ -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: diff --git a/lib/Page/Output/Visitor/Layouts/BlockVisitor.php b/lib/Page/Output/Visitor/Layouts/BlockVisitor.php index 88e6f40..7406b39 100644 --- a/lib/Page/Output/Visitor/Layouts/BlockVisitor.php +++ b/lib/Page/Output/Visitor/Layouts/BlockVisitor.php @@ -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; @@ -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, ) {} @@ -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)]; }