dashboard.rst 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. Dashboard
  2. =========
  3. The Dashboard is the main landing page. By default it lists your mapped models,
  4. as defined by you using ``Admin`` services. This is useful to help you start using
  5. ``SonataAdminBundle`` right away, but there's much more that you can do to take
  6. advantage of the Dashboard.
  7. The Dashboard is, by default, available at ``/admin/dashboard``, which is handled by
  8. the ``SonataAdminBundle:Core:dashboard`` controller action. The default view file for
  9. this action is ``SonataAdminBundle:Core:dashboard.html.twig``, but you can easily change
  10. it in your ``config.yml``:
  11. .. code-block:: yaml
  12. # app/config/config.yml
  13. sonata_admin:
  14. templates:
  15. dashboard: SonataAdminBundle:Core:dashboard.html.twig
  16. .. note::
  17. This view, like most of ``SonataAdminBundle`` views, extends a global
  18. template file, which also contains significant parts to the page. More information
  19. about this is available in the :doc:`templates` chapter.
  20. Blocks
  21. ------
  22. The Dashboard is actually built using ``Blocks`` from ``SonataBlockBundle``. You
  23. can learn more about this bundle and how to build your own Blocks in its `documentation page`_.
  24. An example of a ``Block`` is the above mentioned ``Admin`` list. It is actually implemented as a
  25. ``SonataBlockBundle`` block, that displays your configured ``Admin`` services in a nicely
  26. formated list.
  27. The ``Admin`` list
  28. ------------------
  29. The ``Admin`` list is a ``Block`` that fetches information from the ``Admin`` services ``Pool``
  30. and prints it in the nicely formated list you have on your default Dashboard.
  31. The ``Admin`` list is defined by the ``sonata.admin.block.admin_list`` service, which is
  32. implemented by the ``Block\AdminListBlockService`` class. It is then rendered using the
  33. ``SonataAdminBundle:Block:block_admin_list.html.twig`` template file.
  34. Feel free to take a look at these files. You'll find the code rather small and easy to
  35. understand, and will be a great help when implementing your own blocks.
  36. Configuring the ``Admin`` list
  37. ------------------------------
  38. As you probably noticed by now, the ``Admin`` list groups ``Admin`` mappings together.
  39. There are several ways in which you can configure these groups.
  40. Using the ``Admin`` service declaration
  41. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  42. The first, and most commonly
  43. used, is when defining your ``Admin`` service:
  44. .. code-block:: xml
  45. <service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
  46. <tag name="sonata.admin" manager_type="orm" group="Content" label="Post"/>
  47. <argument />
  48. <argument>Acme\DemoBundle\Entity\Post</argument>
  49. <argument />
  50. </service>
  51. .. code-block:: yaml
  52. services:
  53. sonata.admin.post:
  54. class: Acme\DemoBundle\Admin\PostAdmin
  55. tags:
  56. - { name: sonata.admin, manager_type: orm, group: "Content", label: "Post" }
  57. arguments:
  58. - ~
  59. - Acme\DemoBundle\Entity\Post
  60. - ~
  61. In these examples, notice the ``group`` tag, stating that this particular ``Admin`` service
  62. belongs to the ``Content`` group.
  63. .. code-block:: xml
  64. <service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
  65. <tag name="sonata.admin" manager_type="orm" group="acme.admin.group.content" label="acme.admin.model.post" label_catalogue="AcmeDemoBundle"/>
  66. <argument />
  67. <argument>Acme\DemoBundle\Entity\Post</argument>
  68. <argument />
  69. </service>
  70. .. code-block:: yaml
  71. services:
  72. sonata.admin.post:
  73. class: Acme\DemoBundle\Admin\PostAdmin
  74. tags:
  75. - { name: sonata.admin, manager_type: orm, group: "acme.admin.group.content", label: "acme.admin.model.post", label_catalogue: "AcmeDemoBundle" }
  76. arguments:
  77. - ~
  78. - Acme\DemoBundle\Entity\Post
  79. - ~
  80. The provided labels are actually translated by ``SonataAdminBundle``, using the given
  81. ``label_catalogue``. So, you can use the above examples to support multilanguage
  82. in your project.
  83. Using the ``config.yml``
  84. ^^^^^^^^^^^^^^^^^^^^^^^^
  85. You can also configure the ``Admin`` list in your ``config.yml`` file. This
  86. configuration method overrides the configuration defined as part of the
  87. ``Admin`` services declaration.
  88. .. code-block:: yaml
  89. # app/config/config.yml
  90. sonata_admin:
  91. dashboard:
  92. groups:
  93. acme.admin.group.content:
  94. label: acme.admin.group.content
  95. label_catalogue: AcmeDemoBundle
  96. items:
  97. - sonata.admin.post
  98. acme.admin.group.blog:
  99. items: ~
  100. item_adds:
  101. - sonata.admin.page
  102. roles: [ ROLE_ONE, ROLE_TWO ]
  103. acme.admin.group.misc: ~
  104. .. note::
  105. This is an academic, full configuration example, meaning that in real cases, you may
  106. not need to use all the displayed options. Default values can be used by either
  107. leaving them out of the configuration or by using the ``~`` value in the respective option.
  108. This configuration specifies that the ``acme.admin.group.content`` group uses the
  109. ``acme.admin.group.content`` label, which is translated using the ``AcmeDemoBundle``
  110. translation catalogue. In other words, it's the same configuration that we declared
  111. previously, on the ``Admin`` service.
  112. It also states that the ``acme.admin.group.content`` group contains just the
  113. ``sonata.admin.post`` ``Admin`` mapping, meaning that any other ``Admin`` services
  114. declared as belonging to this group will not be displayed here.
  115. Secondly, we declare a ``acme.admin.group.blog`` as having all its default items
  116. (by default we mean the ones specified in the ``Admin`` services declaration), plus
  117. an additional ``sonata.admin.page`` mapping, that was not initially part of this group.
  118. We also use the ``roles`` option here, used to specify that , instead of being visible
  119. to everyone, only users with ``ROLE_ONE`` or ``ROLE_TWO`` will be able to see this group.
  120. Users with ``ROLE_SUPER_ADMIN`` are always able to see groups that would otherwise be
  121. hidden by this configuration option.
  122. The third group keeps all the default values, as declared on the ``Admin`` service
  123. declaration.
  124. Adding more Blocks
  125. ------------------
  126. Like we said before, the Dashboard comes with a default ``Admin`` list block, but
  127. you can create and add more blocks to it.
  128. .. figure:: ../images/dashboard.png
  129. :align: center
  130. :alt: Dashboard
  131. :width: 500
  132. In this screenshot, you can see how, besides the ``Admin`` list block on the left, we added
  133. a text block and a RSS feed block to the right. The configuration for this scenario would be:
  134. .. code-block:: yaml
  135. # app/config/config.yml
  136. sonata_admin:
  137. dashboard:
  138. blocks:
  139. - { position: left, type: sonata.admin.block.admin_list }
  140. - { position: right, type: sonata.block.service.text, settings: { content: "<h2>Welcome to the Sonata Admin</h2> <p>This is a <code>sonata.block.service.text</code> from the Block Bundle, you can create and add new block in these area by configuring the <code>sonata_admin</code> section.</p> <br /> For instance, here a RSS feed parser (<code>sonata.block.service.rss</code>):"} }
  141. - { position: right, type: sonata.block.service.rss, settings: { title: Sonata Project's Feeds, url: http://sonata-project.org/blog/archive.rss }}
  142. .. note::
  143. Blocks may accept/require additional settings to be passed in order to
  144. work properly. Refer to the associated documentation/implementation to
  145. get more information on each block's options and requirements.
  146. Display two ``Admin`` list blocks with different dashboard groups
  147. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  148. The same block can have multiple instances, and displayed multiple time
  149. across the Dashboard. An particular example is the ``Admin`` list block,
  150. which can be configured to better fit this scenario.
  151. .. code-block:: yaml
  152. # app/config/config.yml
  153. sonata_admin:
  154. dashboard:
  155. blocks:
  156. # display two dashboard blocks
  157. - { position: left, type: sonata.admin.block.admin_list, settings: { groups: [sonata_page1, sonata_page2] } }
  158. - { position: right, type: sonata.admin.block.admin_list, settings: { groups: [sonata_page3] } }
  159. groups:
  160. sonata_page1:
  161. items:
  162. - sonata.page.admin.myitem1
  163. sonata_page2:
  164. items:
  165. - sonata.page.admin.myitem2
  166. - sonata.page.admin.myitem3
  167. sonata_page3:
  168. items:
  169. - sonata.page.admin.myitem4
  170. In this example, you would have two ``Admin`` list blocks on your dashboard, each of
  171. them containing just the respectively configured groups.
  172. .. _`documentation page`: http://sonata-project.org/bundles/block/master/doc/index.html