Skip to content

Commit

Permalink
Breadcrumps subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof committed Oct 11, 2023
1 parent 2c7a5e3 commit 55f32b1
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/lib/EventDispatcher/EventListener/BreadCrumbSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Search\EventDispatcher\EventListener;


use Ibexa\Search\EventDispatcher\Event\PostAutoCompleteSearch;
use Ibexa\Search\Model\Suggestion;
use Symfony\Cmf\Component\Routing\ContentRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class BreadCrumbSubscriber implements EventSubscriberInterface
{


private ContentRepositoryInterface $contentRepository;

public function __construct(ContentRepositoryInterface $contentRepository)
{
$this->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;
}
}

0 comments on commit 55f32b1

Please sign in to comment.