From 55f32b1005d0ef434240124b4cacaf85bea35d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20S=C5=82omka?= Date: Wed, 11 Oct 2023 08:50:42 +0200 Subject: [PATCH] Breadcrumps subscriber --- .../EventListener/BreadCrumbSubscriber.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/lib/EventDispatcher/EventListener/BreadCrumbSubscriber.php diff --git a/src/lib/EventDispatcher/EventListener/BreadCrumbSubscriber.php b/src/lib/EventDispatcher/EventListener/BreadCrumbSubscriber.php new file mode 100644 index 0000000..8b6a58a --- /dev/null +++ b/src/lib/EventDispatcher/EventListener/BreadCrumbSubscriber.php @@ -0,0 +1,47 @@ +contentRepository = $contentRepository; + } + + 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){ + $content = $this->contentRepository->findById($locationId); + $suggestion->addBreadCrumb($locationId, $content->getName()); + } + + } + + return $event; + } +}