From ca79c9c2068ec3f347b5a5e41da902770a1e03b2 Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Wed, 16 Aug 2023 10:44:11 +0200 Subject: [PATCH] Be able to filter the search enabled entities --- dist/src/Resources/config/search/taxons.yaml | 3 ++- src/Controller/SearchController.php | 6 +++++- src/DependencyInjection/Configuration.php | 3 ++- src/DependencyInjection/DocumentableRegistryPass.php | 1 + src/Resources/config/monsieurbiz_search.yaml | 3 ++- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dist/src/Resources/config/search/taxons.yaml b/dist/src/Resources/config/search/taxons.yaml index d4e44060..b644263b 100644 --- a/dist/src/Resources/config/search/taxons.yaml +++ b/dist/src/Resources/config/search/taxons.yaml @@ -3,7 +3,8 @@ monsieurbiz_sylius_search: app_taxon: #prefix: '…' # define a custom index prefix on index names and aliases #document_class: '…' # by default MonsieurBiz\SyliusSearchPlugin\Model\Documentable\Documentable - instant_search_enabled: true # by default false + #search_enabled: true # by default true + #instant_search_enabled: true # by default true limits: search: [9, 18, 27] taxon: [9, 18, 27] diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index abe932d7..e2140573 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -82,8 +82,12 @@ public function searchAction( ); $result = $this->search->search($requestConfiguration); + $documentableRegistries = array_filter($this->documentableRegistry->all(), function (DocumentableInterface $documentable) { + return (bool) $this->searchSettings->getCurrentValue($this->channelContext->getChannel(), null, 'search_enabled__' . $documentable->getIndexCode()); + }); + return $this->render('@MonsieurBizSyliusSearchPlugin/Search/result.html.twig', [ - 'documentableRegistries' => $this->documentableRegistry->all(), + 'documentableRegistries' => $documentableRegistries, 'documentable' => $result->getDocumentable(), 'requestConfiguration' => $requestConfiguration, 'query' => urldecode($query), diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 241dc546..fbe86185 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -37,7 +37,8 @@ public function getConfigTreeBuilder(): TreeBuilder ->children() ->scalarNode('prefix')->defaultValue(null)->end() ->scalarNode('document_class')->defaultValue(Documentable::class)->end() - ->scalarNode('instant_search_enabled')->defaultValue(false)->end() + ->scalarNode('search_enabled')->defaultValue(true)->end() + ->scalarNode('instant_search_enabled')->defaultValue(true)->end() ->scalarNode('source')->isRequired()->cannotBeEmpty()->end() ->scalarNode('target')->isRequired()->cannotBeEmpty()->end() ->scalarNode('mapping_provider')->defaultValue(YamlWithLocaleProvider::class)->end() diff --git a/src/DependencyInjection/DocumentableRegistryPass.php b/src/DependencyInjection/DocumentableRegistryPass.php index dda4d546..39f866ca 100644 --- a/src/DependencyInjection/DocumentableRegistryPass.php +++ b/src/DependencyInjection/DocumentableRegistryPass.php @@ -79,6 +79,7 @@ private function addDocumentableServices(ContainerBuilder $container, array $doc $registry->addMethodCall('register', [$documentableServiceId, new Reference($documentableServiceId)]); // Add the default settings value of documentable + $searchSettings['monsieurbiz.search']['default_values']['search_enabled__' . $indexCode] = $documentableConfiguration['search_enabled']; $searchSettings['monsieurbiz.search']['default_values']['instant_search_enabled__' . $indexCode] = $documentableConfiguration['instant_search_enabled']; $searchSettings['monsieurbiz.search']['default_values']['limits__' . $indexCode] = $documentableConfiguration['limits']; } diff --git a/src/Resources/config/monsieurbiz_search.yaml b/src/Resources/config/monsieurbiz_search.yaml index abdbde9e..7f80794d 100644 --- a/src/Resources/config/monsieurbiz_search.yaml +++ b/src/Resources/config/monsieurbiz_search.yaml @@ -3,7 +3,8 @@ monsieurbiz_sylius_search: monsieurbiz_product: #prefix: '…' # define a custom index prefix on index names and aliases #document_class: '…' # by default MonsieurBiz\SyliusSearchPlugin\Model\Documentable\Documentable - instant_search_enabled: true # by default false + #search_enabled: true # by default true + #instant_search_enabled: true # by default true limits: search: [9, 18, 27] taxon: [9, 18, 27]