Skip to content

Commit

Permalink
Merge pull request #188 from maximehuran/feature/documentable-defaut
Browse files Browse the repository at this point in the history
Manage documentable default to retrieve enable one
  • Loading branch information
maximehuran committed Aug 17, 2023
2 parents 248cba5 + 0c24f5c commit 1930ec3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions src/Controller/SearchController.php
Expand Up @@ -82,12 +82,8 @@ 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' => $documentableRegistries,
'documentableRegistries' => $this->getSearchEnabledDocumentables(),
'documentable' => $result->getDocumentable(),
'requestConfiguration' => $requestConfiguration,
'query' => urldecode($query),
Expand Down Expand Up @@ -120,11 +116,7 @@ public function instantAction(Request $request): Response
{
$results = [];
/** @var DocumentableInterface $documentable */
foreach ($this->documentableRegistry->all() as $documentable) {
if (!(bool) $this->searchSettings->getCurrentValue($this->channelContext->getChannel(), null, 'instant_search_enabled__' . $documentable->getIndexCode())) {
continue;
}

foreach ($this->getInstantSearchEnabledDocumentables() as $documentable) {
$requestConfiguration = new RequestConfiguration(
$request,
RequestInterface::INSTANT_TYPE,
Expand Down Expand Up @@ -170,7 +162,7 @@ public function taxonAction(
private function getDocumentable(?string $documentType): DocumentableInterface
{
if (null === $documentType) {
$documentables = $this->documentableRegistry->all();
$documentables = $this->getSearchEnabledDocumentables();

return reset($documentables);
}
Expand All @@ -182,4 +174,18 @@ private function getDocumentable(?string $documentType): DocumentableInterface
throw new NotFoundHttpException(sprintf('Documentable "%s" not found', $documentType));
}
}

private function getSearchEnabledDocumentables(): array
{
return array_filter($this->documentableRegistry->all(), function (DocumentableInterface $documentable) {
return (bool) $this->searchSettings->getCurrentValue($this->channelContext->getChannel(), null, 'search_enabled__' . $documentable->getIndexCode());
});
}

private function getInstantSearchEnabledDocumentables(): array
{
return array_filter($this->documentableRegistry->all(), function (DocumentableInterface $documentable) {
return (bool) $this->searchSettings->getCurrentValue($this->channelContext->getChannel(), null, 'instant_search_enabled__' . $documentable->getIndexCode());
});
}
}
2 changes: 1 addition & 1 deletion src/Resources/views/Search/_form.html.twig
@@ -1,6 +1,6 @@
{% form_theme form '@SyliusShop/Form/theme.html.twig' %}
<div class="ui form items">
{{ form_start(form, {'action': path('monsieurbiz_search_post'), 'method': 'POST', 'attr': {'class': 'ui search item category autocomplete-search', 'tabindex': '-1'}}) }}
{{ form_start(form, {'action': path('monsieurbiz_search_post'), 'method': 'POST', 'attr': {'class': 'ui search item category autocomplete-search', 'tabindex': '-1', 'autocomplete': 'off'}}) }}
{{ form_errors(form) }}
{{ form_row(form.query, {'value': query, 'label': false}) }}
{{ form_row(form.submit, {'attr': {'class': 'ui primary button'}}) }}
Expand Down

0 comments on commit 1930ec3

Please sign in to comment.