Skip to content

Commit

Permalink
#14790 - Add 'use_parent_location' attribute in ContentSearchHandler
Browse files Browse the repository at this point in the history
The 'use_parent_location' parameter has been included to extend the ContentSearchHandler. This new boolean attribute modifies the buildParentLocationParameters and isContextual methods, allowing for the parent location to be used as the search parameter if activated. Additionally, necessary wordings have been added to the translation files.
  • Loading branch information
tinomaass committed Apr 23, 2024
1 parent 9188832 commit cc5ad92
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
14 changes: 14 additions & 0 deletions CHANGELOG_CJW
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Changelogfor CJW Stack
===========================================================

20240423 - Extend ContentSearchHandler > ParentLocationTrait
------------------------------------------------------------

Set new boolean attribute "use_parent_location" for ParentLocationTrait:
vendor/netgen/layouts-ibexa/lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php

Extend ContentSearchHandler:
vendor/netgen/layouts-ibexa/lib/Collection/QueryType/Handler/ContentSearchHandler.php

Set translation for new attribute:
vendor/netgen/layouts-ibexa/bundle/Resources/translations/nglayouts.en.yaml
5 changes: 5 additions & 0 deletions bundle/Resources/translations/nglayouts.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ block.ibexa_content_field.field_identifier: 'Field identifier'
block.ibexa_component.content: 'Content'

query.ibexa_content_search.use_current_location: 'Use current location as parent'

# CJW Stack
query.ibexa_content_search.use_parent_location: 'Use parent location as parent'
# -- CJW Stack

query.ibexa_content_search.parent_location_id: 'Parent location'
query.ibexa_content_search.sort_direction: 'Sort direction'
query.ibexa_content_search.sort_type: 'Sort type'
Expand Down
6 changes: 5 additions & 1 deletion lib/Collection/QueryType/Handler/ContentSearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public function getCount(Query $query): int

public function isContextual(Query $query): bool
{
return $query->getParameter('use_current_location')->getValue() === true;
// CJW Stack
return $query->getParameter('use_current_location')->getValue() === true || $query->getParameter('use_parent_location')->getValue() === true;
// -- CJW Stack

//return $query->getParameter('use_current_location')->getValue() === true;
}

/**
Expand Down
20 changes: 20 additions & 0 deletions lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ private function setLocationService(LocationService $locationService): void
*/
private function buildParentLocationParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
//
// CJW Stack
//

$builder->add(
'use_parent_location',
ParameterType\Compound\BooleanType::class,
[
'groups' => $groups,
],
);

// -- CJW Stack

$builder->add(
'use_current_location',
ParameterType\Compound\BooleanType::class,
Expand Down Expand Up @@ -69,6 +83,12 @@ private function getParentLocation(ParameterCollectionInterface $parameterCollec
if ($parameterCollection->getParameter('use_current_location')->getValue() === true) {
return $this->contentProvider->provideLocation();
}
// CJW Stack
elseif ( $parameterCollection->getParameter('use_parent_location')->getValue() === true )
{
return $this->contentProvider->provideLocation()->getParentLocation();
}
// -- CJW Stack

$parentLocationId = $parameterCollection->getParameter('parent_location_id')->getValue();
if ($parentLocationId === null) {
Expand Down

0 comments on commit cc5ad92

Please sign in to comment.