-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
438 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
Persisting Filters | ||
================== | ||
|
||
Persisting filters allow your application to save the filters the authenticated | ||
user has submitted. | ||
Then the saved filters will be reused if the page is displayed again. | ||
|
||
|
||
Enable Filters Persistence | ||
-------------------------- | ||
|
||
By default, filters persistence is disabled. | ||
You can enable it in your ``sonata_admin`` configuration : | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
# app/config/config.yml | ||
sonata_admin: | ||
persist_filters: true | ||
Choose the persistence strategy | ||
------------------------------- | ||
|
||
When you enable the filters persistence by setting ``persist_filters`` | ||
to ``true``. | ||
SonataAdmin will use the default filter persister : | ||
``Sonata\AdminBundle\Filter\Persister\SessionFilterPersister`` | ||
(which is, by now, the only one provided). | ||
|
||
You can implement your own filter persister by creating a new class that | ||
implements the ``Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface`` | ||
interface and registering it as a service. | ||
Then the only thing to do is to tell SonataAdmin to use this service as | ||
filter persister. | ||
|
||
|
||
Globally : | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
# app/config/config.yml | ||
sonata_admin: | ||
persist_filters: true | ||
filter_persister: filter_persister_service_id | ||
Per Admin : | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: xml | ||
<!-- src/AppBundle/Resources/config/admin.xml --> | ||
<service id="app.admin.user" class="AppBundle\Admin\UserAdmin"> | ||
<tag name="sonata.admin" manager_type="orm" filter_persister="filter_persister_service_id" /> | ||
<argument /> | ||
<argument>AppBundle\Entity\User</argument> | ||
<argument /> | ||
</service> | ||
.. code-block:: yaml | ||
# src/AppBundle/Resources/config/admin.yml | ||
services: | ||
app.admin.user: | ||
class: AppBundle\Admin\UserAdmin | ||
tags: | ||
- | ||
name: sonata.admin | ||
manager_type: orm | ||
filter_persister: filter_persister_service_id | ||
arguments: | ||
- null | ||
- AppBundle\Entity\User | ||
- null | ||
Disable filters persistence for some Admin | ||
------------------------------------------ | ||
|
||
When you enable the filters persistence by setting ``persist_filters`` | ||
to ``true``. | ||
All registered Admins will have the feature enabled. | ||
|
||
You can disable it per Admin if you want. | ||
|
||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: xml | ||
<!-- src/AppBundle/Resources/config/admin.xml --> | ||
<service id="app.admin.user" class="AppBundle\Admin\UserAdmin"> | ||
<tag name="sonata.admin" manager_type="orm" persist_filters="false" /> | ||
<argument /> | ||
<argument>AppBundle\Entity\User</argument> | ||
<argument /> | ||
</service> | ||
.. code-block:: yaml | ||
# src/AppBundle/Resources/config/admin.yml | ||
services: | ||
app.admin.user: | ||
class: AppBundle\Admin\UserAdmin | ||
tags: | ||
- | ||
name: sonata.admin | ||
manager_type: orm | ||
persist_filters: false | ||
arguments: | ||
- null | ||
- AppBundle\Entity\User | ||
- null | ||
.. note:: | ||
|
||
Both ``persist_filters`` and ``filter_persister`` can be used globally | ||
and per-admin, which provide you the most flexible way to configure | ||
this feature. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Filter\Persister; | ||
|
||
/** | ||
* Filter persister are components responsible for storing filters for given admin. | ||
* So filters are not lost when you navigate. | ||
* | ||
* @author Yann Eugoné <eugone.yann@gmail.com> | ||
*/ | ||
interface FilterPersisterInterface | ||
{ | ||
/** | ||
* Get persisted filters for given admin. | ||
* | ||
* @param string $adminCode The admin code | ||
* | ||
* @return array The persisted filters | ||
*/ | ||
public function get($adminCode); | ||
|
||
/** | ||
* Set persisted filters for given admin. | ||
* | ||
* @param string $adminCode The admin code | ||
* @param array $filters The filters to persist. Structure : | ||
* {string filter field} => array( | ||
* "type" => {int filter type}, | ||
* "value" => {mixed filter value}, | ||
* ), | ||
* ..., | ||
* "_page" => {int page num}, | ||
* "_sort_by" => {string sort property}, | ||
* "_sort_order" => {string sort order (ASC|DESC)}, | ||
* "_per_page" => {int count rows per page} | ||
*/ | ||
public function set($adminCode, array $filters); | ||
|
||
/** | ||
* Reset persisted filters for given admin. | ||
* | ||
* @param string $adminCode The admin code | ||
*/ | ||
public function reset($adminCode); | ||
} |
Oops, something went wrong.