Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation for Issue #7 - Add 'use_parent_location' attribute in Ibexa ContentSearchHandler #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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/translations/nglayouts.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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'
query.ibexa_content_search.use_parent_location: 'Use parent location as parent'
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
2 changes: 1 addition & 1 deletion lib/Collection/QueryType/Handler/ContentSearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getCount(Query $query): int

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

/**
Expand Down
18 changes: 18 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,14 @@ private function setLocationService(LocationService $locationService): void
*/
private function buildParentLocationParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'use_parent_location',
ParameterType\Compound\BooleanType::class,
[
'groups' => $groups,
],
);

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

if ( $currentLocation instanceof Location )
{
return $currentLocation->getParentLocation();
}

}

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