diff --git a/src/lib/EventDispatcher/EventListener/BreadCrumbSubscriber.php b/src/lib/EventDispatcher/EventListener/BreadCrumbSubscriber.php new file mode 100644 index 0000000..34e33a2 --- /dev/null +++ b/src/lib/EventDispatcher/EventListener/BreadCrumbSubscriber.php @@ -0,0 +1,43 @@ +locationService = $locationService; + } + + public static function getSubscribedEvents(): array + { + return [ + PostAutoCompleteSearch::class => 'onPostAutoCompleteSearch', + ]; + } + + public function onPostAutoCompleteSearch(PostAutoCompleteSearch $event): PostAutoCompleteSearch + { + /** @var Suggestion $suggestion */ + foreach ($event->getSuggestionCollection() as $suggestion){ + foreach ($suggestion->getParentsLocation() as $locationId => $name){ + $location = $this->locationService->loadLocation($locationId); + $suggestion->addPath($locationId, $location->contentInfo->name); + } + + } + + return $event; + } +} diff --git a/src/lib/Mapper/SearchResultToSuggestionCollectionMapper.php b/src/lib/Mapper/SearchResultToSuggestionCollectionMapper.php index c095fd0..3d57fa2 100644 --- a/src/lib/Mapper/SearchResultToSuggestionCollectionMapper.php +++ b/src/lib/Mapper/SearchResultToSuggestionCollectionMapper.php @@ -26,7 +26,7 @@ public function transform(SearchResult $searchResult, ?string $language = null): $content->getFieldValue('title', $language)->text, $result->valueObject->contentInfo->getContentType()->identifier, $result->valueObject->contentInfo->mainLocation->pathString, - $result->valueObject->contentInfo->mainLocation->path + array_flip($result->valueObject->contentInfo->mainLocation->path) ); } diff --git a/src/lib/Model/Suggestion.php b/src/lib/Model/Suggestion.php index 4d4f9b5..6d6ecc5 100644 --- a/src/lib/Model/Suggestion.php +++ b/src/lib/Model/Suggestion.php @@ -58,4 +58,9 @@ public function getParentsLocation(): array { return $this->parentsLocation; } + + public function addPath(int $locationId, string $name) + { + $this->parentsLocation[$locationId] = $name; + } }