Skip to content

Commit

Permalink
empty boxes configuration docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kunicmarko20 authored and greg0ire committed Mar 3, 2018
1 parent 7bfe01d commit 570e7a6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
Binary file added docs/images/empty_boxes_fade.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/empty_boxes_hide.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/empty_boxes_show.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 61 additions & 5 deletions docs/reference/search.rst
Expand Up @@ -17,37 +17,43 @@ The default template values can be configured in the configuration section

.. code-block:: yaml
# app/config/config.yml
# config/packages/sonata_admin.yaml
sonata_admin:
templates:
# other configuration options
search: '@SonataAdmin/Core/search.html.twig'
search_result_block: '@SonataAdmin/Block/block_search_result.html.twig'
.. note::
If you are not using Symfony Flex, this should be added to ``app/config/config.yml``.

You also need to configure the block in the sonata block config

.. configuration-block::

.. code-block:: yaml
# app/config/config.yml
# config/packages/sonata_admin.yaml
sonata_block:
blocks:
sonata.admin.block.search_result:
contexts: [admin]
.. note::
If you are not using Symfony Flex, this should be added to ``app/config/config.yml``.

You can also configure the block template per admin while defining the admin:

.. configuration-block::

.. code-block:: xml
<service id="app.admin.post" class="AppBundle\Admin\PostAdmin">
<service id="app.admin.post" class="App\Admin\PostAdmin">
<tag name="sonata.admin" manager_type="orm" group="Content" label="Post" />
<argument />
<argument>AppBundle\Entity\Post</argument>
<argument>App\Entity\Post</argument>
<argument />
<call method="setTemplate">
<argument>search_result_block</argument>
Expand All @@ -66,7 +72,7 @@ permissions exists. If no route is found, the item will be displayed as a text.
.. code-block:: php
<?php
// src/AppBundle/Admin/PersonAdmin.php
// src/Admin/PersonAdmin.php
class PersonAdmin extends AbstractAdmin
{
Expand All @@ -85,3 +91,53 @@ The current implementation can be expensive if you have a lot of entities as the
.. note::

There is a work in progress to use an async JavaScript solution to better load data from the database.

Customize visibility of empty result boxes
------------------------------------------

By default all the admin boxes are shown in search results and it looks like this:

.. figure:: ../images/empty_boxes_show.png
:align: center
:alt: Custom view
:width: 700px

We can fade out the boxes that have no results with:

.. code-block:: yaml
# config/packages/sonata_admin.yaml
sonata_admin:
global_search:
empty_boxes: fade
.. note::
If you are not using Symfony Flex, this should be added to ``app/config/config.yml``.

and it looks like this:

.. figure:: ../images/empty_boxes_fade.png
:align: center
:alt: Custom view
:width: 700px

The third option is to hide the empty boxes:

.. code-block:: yaml
# config/packages/sonata_admin.yaml
sonata_admin:
global_search:
empty_boxes: hide
.. note::
If you are not using Symfony Flex, this should be added to ``app/config/config.yml``.

and it looks like this:

.. figure:: ../images/empty_boxes_hide.png
:align: center
:alt: Custom view
:width: 700px

0 comments on commit 570e7a6

Please sign in to comment.