Skip to content

Commit eaf9301

Browse files
authored
Merge pull request #13 from netgen/PROSTSUPP-187-tag-default-block-query-collection-with-parent-location
PROSTSUPP-187-tag-default-block-query-collection-with-parent-location
2 parents f5bfa66 + 8ac9656 commit eaf9301

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

bundle/Resources/config/services/page/visitors.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ services:
4848
netgen.openapi_ibexa.page.output.visitor.layouts.block:
4949
class: Netgen\OpenApiIbexa\Page\Output\Visitor\Layouts\BlockVisitor
5050
arguments:
51+
- '@Ibexa\HttpCache\Handler\TagHandler'
5152
- '@netgen_layouts.collection.result.pagerfanta.factory'
5253
- '@ibexa.config.resolver'
5354
tags:

lib/Page/Output/Visitor/Layouts/BlockVisitor.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Generator;
88
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
9+
use Ibexa\HttpCache\Handler\TagHandler;
910
use Netgen\IbexaSiteApi\API\Values\Content;
1011
use Netgen\IbexaSiteApi\API\Values\Location;
1112
use Netgen\Layouts\API\Values\Block\Block;
@@ -18,12 +19,15 @@
1819
use Netgen\OpenApiIbexa\Page\Output\VisitorInterface;
1920
use ReflectionClass;
2021

22+
use function is_int;
23+
2124
/**
2225
* @implements \Netgen\OpenApiIbexa\Page\Output\VisitorInterface<\Netgen\Layouts\API\Values\Block\Block>
2326
*/
2427
final class BlockVisitor implements VisitorInterface
2528
{
2629
public function __construct(
30+
private TagHandler $tagHandler,
2731
private PagerFactory $pagerFactory,
2832
private ConfigResolverInterface $configResolver,
2933
) {}
@@ -48,11 +52,24 @@ public function visit(object $value, OutputVisitor $outputVisitor, array $parame
4852
];
4953

5054
if ($value->hasCollection('default')) {
55+
/** @var \Netgen\Layouts\API\Values\Collection\Collection $collection */
56+
$collection = $value->getCollection('default');
57+
5158
/** @var \Netgen\Layouts\Collection\Result\ResultSet $resultSet */
5259
$resultSet = $this->pagerFactory
53-
->getPager($value->getCollection('default'), 1)
60+
->getPager($collection, 1)
5461
->getCurrentPageResults();
5562

63+
$query = $collection->getQuery();
64+
65+
$parentLocation = $query?->hasParameter('parent_location_id') === true
66+
? $query->getParameter('parent_location_id')->getValue()
67+
: null;
68+
69+
if (is_int($parentLocation)) {
70+
$this->tagHandler->addLocationTags([$parentLocation]);
71+
}
72+
5673
$properties['items'] = [...$this->visitItems($resultSet, $outputVisitor)];
5774
}
5875

0 commit comments

Comments
 (0)