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

Show applied filter #6225

Merged
merged 5 commits into from
Jul 30, 2020
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
7 changes: 7 additions & 0 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,8 @@ final public function getSearchResultLink($object)
}

/**
* NEXT_MAJOR: remove this method.
kirya-dev marked this conversation as resolved.
Show resolved Hide resolved
*
* Checks if a filter type is set to a default value.
*
* @param string $name
Expand All @@ -3162,6 +3164,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
kirya-dev marked this conversation as resolved.
Show resolved Hide resolved
// 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