From 53839b5ef00a3e0ff2f4fc7f7d275dcfb52f2857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LESCALLIER?= Date: Wed, 29 Apr 2020 13:23:35 +0200 Subject: [PATCH] Add event dispatch for customize autocomplete item --- Model/Autocomplete/Page/DataProvider.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Model/Autocomplete/Page/DataProvider.php b/Model/Autocomplete/Page/DataProvider.php index 8f51d97..3d72a62 100644 --- a/Model/Autocomplete/Page/DataProvider.php +++ b/Model/Autocomplete/Page/DataProvider.php @@ -20,6 +20,7 @@ use Smile\ElasticsuiteCore\Helper\Autocomplete as ConfigurationHelper; use Smile\ElasticsuiteCms\Model\ResourceModel\Page\Fulltext\CollectionFactory as CmsCollectionFactory; use Smile\ElasticsuiteCore\Model\Autocomplete\Terms\DataProvider as TermDataProvider; +use Magento\Framework\Event\ManagerInterface as EventManager; /** * Catalog product autocomplete data provider. @@ -71,6 +72,11 @@ class DataProvider implements DataProviderInterface */ protected $storeManager; + /** + * @var EventManager + */ + protected $eventManager; + /** * @var string Autocomplete result type */ @@ -85,6 +91,7 @@ class DataProvider implements DataProviderInterface * @param CmsCollectionFactory $cmsCollectionFactory Cms collection factory. * @param ConfigurationHelper $configurationHelper Autocomplete configuration helper. * @param StoreManagerInterface $storeManager Store manager. + * @param EventManager $eventManager Event dispatcher * @param string $type Autocomplete provider type. */ public function __construct( @@ -94,6 +101,7 @@ public function __construct( CmsCollectionFactory $cmsCollectionFactory, ConfigurationHelper $configurationHelper, StoreManagerInterface $storeManager, + EventManager $eventManager, $type = self::AUTOCOMPLETE_TYPE ) { $this->itemFactory = $itemFactory; @@ -101,6 +109,7 @@ public function __construct( $this->termDataProvider = $termDataProvider; $this->cmsCollectionFactory = $cmsCollectionFactory; $this->configurationHelper = $configurationHelper; + $this->eventManager = $eventManager; $this->type = $type; $this->storeManager = $storeManager; } @@ -121,13 +130,20 @@ public function getItems() $pageCollection = $this->getCmsPageCollection(); if ($pageCollection) { foreach ($pageCollection as $page) { - $result[] = $this->itemFactory->create( + $item = $this->itemFactory->create( [ 'title' => $page->getTitle(), 'url' => $this->storeManager->getStore()->getBaseUrl(). $page->getIdentifier(), 'type' => $this->getType(), ] ); + + $this->eventManager->dispatch( + 'smile_elasticsuite_cms_search_autocomplete_page_item', + ['page' => $page, 'item' => $item] + ); + + $result[] = $item; } }