Skip to content

Commit

Permalink
Show applied filter (#6225)
Browse files Browse the repository at this point in the history
* Show applied filter

* Resolve issue comments

* Update AdminTest.php

* Update tests/Admin/AdminTest.php

Co-authored-by: Vincent Langlet <[email protected]>

* Update tests/Admin/AdminTest.php

Co-authored-by: Vincent Langlet <[email protected]>

Co-authored-by: Kirill Matasov <[email protected]>
Co-authored-by: Vincent Langlet <[email protected]>
  • Loading branch information
3 people authored Jul 30, 2020
1 parent 7d92242 commit 5539f02
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3165,6 +3165,8 @@ final public function getSearchResultLink($object)
}

/**
* NEXT_MAJOR: remove this method.
*
* Checks if a filter type is set to a default value.
*
* @param string $name
Expand All @@ -3173,6 +3175,11 @@ final public function getSearchResultLink($object)
*/
final public function isDefaultFilter($name)
{
@trigger_error(sprintf(
'Method "%s" is deprecated since sonata-project/admin-bundle 3.x.',
__METHOD__
), E_USER_DEPRECATED);

$filter = $this->getFilterParameters();
$default = $this->getDefaultFilterValues();

Expand Down
8 changes: 1 addition & 7 deletions src/Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @method array configureActionButtons(string $action, ?object $object = null)
* @method string getSearchResultLink(object $object)
* @method void showMosaicButton(bool $isShown)
* @method bool isDefaultFilter(string $name)
* @method bool isDefaultFilter(string $name) // NEXT_MAJOR: Remove this
* @method bool isCurrentRoute(string $name, ?string $adminCode)
* @method bool canAccessObject(string $action, object $object)
* @method mixed getPersistentParameter(string $name)
Expand Down Expand Up @@ -741,12 +741,6 @@ public function getListMode();
// */
// public function showMosaicButton(bool $isShown): void;

/*
* Checks if a filter type is set to a default value
*/
// NEXT_MAJOR: uncomment this method in 4.0
// public function isDefaultFilter(string $name): bool;

// NEXT_MAJOR: uncomment this method in 4.0
// public function setFilterPersister(?\Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface\FilterPersisterInterface $filterPersister = null): void;

Expand Down
12 changes: 6 additions & 6 deletions src/Resources/views/CRUD/base_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ file that was distributed with this source code.
</a>

<ul class="dropdown-menu" role="menu">
{% for filter in admin.datagrid.filters|filter(filter => filter.options['show_filter'] is same as(true) or filter.options['show_filter'] is null) %}
{% set filterActive = ((filter.isActive() or filter.options['show_filter']) and not admin.isDefaultFilter(filter.formName)) %}
{% for filter in admin.datagrid.filters|filter(filter => filter.options['show_filter'] is not same as (false)) %}
{% set filterDisplayed = filter.isActive() or filter.options['show_filter'] is same as (true) %}
<li>
<a href="#" class="sonata-toggle-filter sonata-ba-action" filter-target="filter-{{ admin.uniqid }}-{{ filter.name }}" filter-container="filter-container-{{ admin.uniqid() }}">
<i class="fa {{ (filter.isActive() or filter.options['show_filter']) ? 'fa-check-square-o' : 'fa-square-o' }}"></i>
<i class="fa {{ filterDisplayed ? 'fa-check-square-o' : 'fa-square-o' }}"></i>
{% if filter.label is not same as(false) %}
{{ filter.label|trans({}, filter.translationDomain ?: admin.translationDomain) }}
{% endif %}
Expand All @@ -275,9 +275,9 @@ file that was distributed with this source code.
<div class="col-sm-9">
{% set withAdvancedFilter = false %}
{% for filter in admin.datagrid.filters %}
{% set filterActive = ((filter.isActive() and filter.options['show_filter'] is null) or (filter.options['show_filter'] is same as(true))) and not admin.isDefaultFilter(filter.formName) %}
{% set filterVisible = filter.options['show_filter'] is same as(true) or filter.options['show_filter'] is null %}
<div class="form-group {% block sonata_list_filter_group_class %}{% endblock %}" id="filter-{{ admin.uniqid }}-{{ filter.name }}" sonata-filter="{{ filterVisible ? 'true' : 'false' }}" style="display: {% if filterActive %}block{% else %}none{% endif %}">
{% set filterDisplayed = filter.isActive() or filter.options['show_filter'] is same as (true) %}
{% set filterCanBeDisplayed = filter.options['show_filter'] is not same as(false) %}
<div class="form-group {% block sonata_list_filter_group_class %}{% endblock %}" id="filter-{{ admin.uniqid }}-{{ filter.name }}" sonata-filter="{{ filterCanBeDisplayed ? 'true' : 'false' }}" style="display: {% if filterDisplayed %}block{% else %}none{% endif %}">
{% if filter.label is not same as(false) %}
<label for="{{ form[filter.formName].children['value'].vars.id }}" class="col-sm-3 control-label">{{ filter.label|trans({}, filter.translationDomain ?: admin.translationDomain) }}</label>
{% endif %}
Expand Down
7 changes: 7 additions & 0 deletions tests/Admin/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,13 @@ public function testDefaultDashboardActionsArePresent(string $objFqn, string $ex
$this->assertArrayHasKey('create', $admin->getDashboardActions());
}

/**
* NEXT_MAJOR: Remove the assertion about isDefaultFilter method and the legacy group.
*
* @group legacy
*
* @expectedDeprecation Method "Sonata\AdminBundle\Admin\AbstractAdmin::isDefaultFilter" is deprecated since sonata-project/admin-bundle 3.x.
*/
public function testDefaultFilters(): void
{
$admin = new FilteredAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'Sonata\FooBundle\Controller\ModelAdminController');
Expand Down

0 comments on commit 5539f02

Please sign in to comment.