From ad41270fcba8be3f0e7cac0e5f459499e4362e1e Mon Sep 17 00:00:00 2001 From: tinomaass Date: Thu, 25 Apr 2024 14:22:26 +0200 Subject: [PATCH] Issue #7: Remove CJW stack comments and fix error if $this->contentProvider->provideLocation() doesnt return a location --- CHANGELOG_CJW | 14 -------------- bundle/Resources/translations/nglayouts.en.yaml | 4 ---- .../QueryType/Handler/ContentSearchHandler.php | 4 ---- .../Handler/Traits/ParentLocationTrait.php | 16 +++++++--------- 4 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 CHANGELOG_CJW diff --git a/CHANGELOG_CJW b/CHANGELOG_CJW deleted file mode 100644 index 24d25c87..00000000 --- a/CHANGELOG_CJW +++ /dev/null @@ -1,14 +0,0 @@ -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 diff --git a/bundle/Resources/translations/nglayouts.en.yaml b/bundle/Resources/translations/nglayouts.en.yaml index b8754093..36808882 100644 --- a/bundle/Resources/translations/nglayouts.en.yaml +++ b/bundle/Resources/translations/nglayouts.en.yaml @@ -3,11 +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' - -# 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' diff --git a/lib/Collection/QueryType/Handler/ContentSearchHandler.php b/lib/Collection/QueryType/Handler/ContentSearchHandler.php index 1d438be8..404b443d 100644 --- a/lib/Collection/QueryType/Handler/ContentSearchHandler.php +++ b/lib/Collection/QueryType/Handler/ContentSearchHandler.php @@ -115,11 +115,7 @@ public function getCount(Query $query): int public function isContextual(Query $query): bool { - // 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; } /** diff --git a/lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php b/lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php index 1f3cff68..7a5207b7 100644 --- a/lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php +++ b/lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php @@ -42,10 +42,6 @@ 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, @@ -54,8 +50,6 @@ private function buildParentLocationParameters(ParameterBuilderInterface $builde ], ); - // -- CJW Stack - $builder->add( 'use_current_location', ParameterType\Compound\BooleanType::class, @@ -83,12 +77,16 @@ 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(); + $currentLocation = $this->contentProvider->provideLocation(); + + if ( $currentLocation instanceof Location ) + { + return $currentLocation->getParentLocation(); + } + } - // -- CJW Stack $parentLocationId = $parameterCollection->getParameter('parent_location_id')->getValue(); if ($parentLocationId === null) {