-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/lib/EventDispatcher/EventListener/BreadCrumbSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
final class BreadCrumbSubscriber implements EventSubscriberInterface | ||
{ | ||
private \Ibexa\Contracts\Core\Repository\LocationService $locationService; | ||
|
||
public function __construct(\Ibexa\Contracts\Core\Repository\LocationService $locationService) | ||
{ | ||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters