Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert: Show matching filters in search results #7376

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/Block/AdminSearchBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Filter\FilterInterface;
use Sonata\AdminBundle\Search\SearchHandler;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
Expand Down Expand Up @@ -154,11 +153,9 @@ public function execute(BlockContextInterface $blockContext, ?Response $response

$admin->checkAccess('list');

$term = $blockContext->getSetting('query');

$pager = $this->searchHandler->search(
$admin,
$term,
$blockContext->getSetting('query'),
$blockContext->getSetting('page'),
$blockContext->getSetting('per_page')
);
Expand All @@ -169,18 +166,12 @@ public function execute(BlockContextInterface $blockContext, ?Response $response
return $response->setContent('')->setStatusCode(204);
}

$filters = array_filter($admin->getDatagrid()->getFilters(), static function (FilterInterface $filter): bool {
return $filter->isActive();
});

return $this->renderPrivateResponse($admin->getTemplate('search_result_block'), [
'block' => $blockContext->getBlock(),
'settings' => $blockContext->getSettings(),
// NEXT_MAJOR: Remove next line.
'admin_pool' => $this->pool,
'pager' => $pager,
'term' => $term,
'filters' => $filters,
'admin' => $admin,
'show_empty_boxes' => $this->emptyBoxesOption,
], $response);
Expand Down
10 changes: 0 additions & 10 deletions src/Resources/public/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,6 @@ body.fixed .content-header .navbar.stuck {
word-wrap: break-word;
}

.sonata-search-result-list.nav-stacked > li.item > span.matches {
position: relative;
display: block;
padding: 10px 15px;
}

.sonata-search-result-list.nav-stacked > li.item > span.matches > a.label {
margin: 0 1px;
}

.form-actions.stuck {
position:fixed;
bottom:0;
Expand Down
28 changes: 2 additions & 26 deletions src/Resources/views/Block/block_search_result.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,11 @@ file that was distributed with this source code.
</div>
{% if results_count > 0 %}
<div class="box-body no-padding">
<ul class="nav nav-stacked sonata-search-result-list products-list">
<ul class="nav nav-stacked sonata-search-result-list">
{% for result in current_page_results %}
{% set link = admin.getSearchResultLink(result) %}
{% if link %}
<li class="item no-padding">
<a class="main pull-left" href="{{ link }}">{{ admin.toString(result) }}</a>
<span class="matches pull-right">
{% for name, filter in filters %}
{% set match = name|split('.')|reduce((carry, v) => carry ? attribute(carry, v) : null, result) %}

{#
Some model managers are not respecting the "sonata_admin.global_search.case_sensitive" configuration option.
If you see no matching filters for a search result, it is probably the reason. In that case,
you SHOULD consider using `false` as value for this option.
#}
{% if match and ((filter.option('case_sensitive') is not same as(false) and term in match)
or filter.option('case_sensitive') is same as(false) and term|lower in match|lower)
%}
<a class="label label-primary" href="{{ admin.generateUrl('list', {'filter': {(filter.formName): {'value': term}}}) }}">
{% if filter.option('translation_domain') is same as(false) %}
{{ filter.option('label') }}
{% else %}
{{ filter.option('label')|trans({}, filter.option('translation_domain', admin.translationDomain)) }}
{% endif %}
</a>
{% endif %}
{% endfor %}
</span>
</li>
<li><a href="{{ link }}">{{ admin.toString(result) }}</a></li>
{% else %}
<li><a>{{ admin.toString(result) }}</a></li>
{% endif %}
Expand Down