dashboard.rst 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. Dashboard
  2. =========
  3. The Dashboard is the main landing page. By default it lists your mapped models,
  4. as defined by your ``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 change
  10. this 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 the ``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 on the
  24. `SonataBlock documentation page`_.
  25. The ``Admin`` list
  26. ------------------
  27. The ``Admin`` list is a ``Block`` that fetches information from the ``Admin`` service's
  28. ``Pool`` and prints it in the nicely formated list you have on your default Dashboard.
  29. The ``Admin`` list is defined by the ``sonata.admin.block.admin_list`` service, which is
  30. implemented by the ``Block\AdminListBlockService`` class. It is then rendered using the
  31. ``SonataAdminBundle:Block:block_admin_list.html.twig`` template file.
  32. Feel free to take a look at these files. You'll find the code rather short and easy to
  33. understand, and it will be a great help when implementing your own blocks.
  34. Configuring the ``Admin`` list
  35. ------------------------------
  36. As you probably noticed by now, the ``Admin`` list groups ``Admin`` mappings together.
  37. There are several ways in which you can configure these groups.
  38. Using the ``Admin`` service declaration
  39. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  40. The first, and most commonly used, method is to set a group when defining your ``Admin``
  41. services:
  42. .. code-block:: xml
  43. <service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
  44. <tag name="sonata.admin" manager_type="orm"
  45. group="Content"
  46. 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
  57. manager_type: orm
  58. group: "Content"
  59. label: "Post"
  60. arguments:
  61. - ~
  62. - Acme\DemoBundle\Entity\Post
  63. - ~
  64. In these examples, notice the ``group`` tag, stating that this particular ``Admin``
  65. service belongs to the ``Content`` group.
  66. .. code-block:: xml
  67. <service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
  68. <tag name="sonata.admin" manager_type="orm"
  69. group="acme.admin.group.content"
  70. label="acme.admin.model.post" label_catalogue="AcmeDemoBundle"/>
  71. <argument />
  72. <argument>Acme\DemoBundle\Entity\Post</argument>
  73. <argument />
  74. </service>
  75. .. code-block:: yaml
  76. services:
  77. sonata.admin.post:
  78. class: Acme\DemoBundle\Admin\PostAdmin
  79. tags:
  80. - name: sonata.admin
  81. manager_type: orm
  82. group: "acme.admin.group.content"
  83. label: "acme.admin.model.post"
  84. label_catalogue: "AcmeDemoBundle"
  85. arguments:
  86. - ~
  87. - Acme\DemoBundle\Entity\Post
  88. - ~
  89. In this example, the labels are translated by ``SonataAdminBundle``, using the given
  90. ``label_catalogue``. So, you can use the above examples to support multiple languages
  91. in your project.
  92. .. note::
  93. You can use parameters (e.g. ``%acme_admin.group_post%``) for the group names
  94. in either scenario.
  95. Using the ``config.yml``
  96. ^^^^^^^^^^^^^^^^^^^^^^^^
  97. You can also configure the ``Admin`` list in your ``config.yml`` file. This
  98. configuration method overrides the any settings defined in the Admin service
  99. declarations.
  100. .. code-block:: yaml
  101. # app/config/config.yml
  102. sonata_admin:
  103. dashboard:
  104. groups:
  105. acme.admin.group.content:
  106. label: acme.admin.group.content
  107. label_catalogue: AcmeDemoBundle
  108. items:
  109. - sonata.admin.post
  110. acme.admin.group.blog:
  111. items: ~
  112. item_adds:
  113. - sonata.admin.page
  114. roles: [ ROLE_ONE, ROLE_TWO ]
  115. acme.admin.group.misc: ~
  116. .. note::
  117. This is an academic, full configuration, example. In real cases, you will usually
  118. not need to use all the displayed options. To use a default value for any setting
  119. either leave out that key or use the ``~`` value for that option.
  120. This configuration specifies that the ``acme.admin.group.content`` group uses the
  121. ``acme.admin.group.content`` label, which is translated using the ``AcmeDemoBundle``
  122. translation catalogue (the same label and translation configuration that we declared
  123. previously, in the service definition example).
  124. It also states that the ``acme.admin.group.content`` group contains just the
  125. ``sonata.admin.post`` ``Admin`` mapping, meaning that any other ``Admin`` services
  126. declared as belonging to this group will not be displayed here.
  127. Secondly, we declare a ``acme.admin.group.blog`` group as having all its default items
  128. (i.e. the ones specified in the ``Admin`` service declarations), plus an *additional*
  129. ``sonata.admin.page`` mapping, that was not initially part of this group.
  130. We also use the ``roles`` option here, which means that only users with the ``ROLE_ONE``
  131. or ``ROLE_TWO`` privileges will be able to see this group, as opposed to the default setting
  132. which allows everyone to see a given group. Users with ``ROLE_SUPER_ADMIN`` are always
  133. able to see groups that would otherwise be hidden by this configuration option.
  134. The third group, ``acme.admin.group.misc``, is set up as a group which uses all its
  135. default values, as declared in the service declarations.
  136. Adding more Blocks
  137. ------------------
  138. Like we said before, the Dashboard comes with a default ``Admin`` list block, but
  139. you can create and add more blocks to it.
  140. .. figure:: ../images/dashboard.png
  141. :align: center
  142. :alt: Dashboard
  143. :width: 500
  144. In this screenshot, in addition to the default ``Admin`` list block on the left, we added
  145. a text block and RSS feed block on the right. The configuration for this scenario would be:
  146. .. code-block:: yaml
  147. # app/config/config.yml
  148. sonata_admin:
  149. dashboard:
  150. blocks:
  151. -
  152. position: left
  153. type: sonata.admin.block.admin_list
  154. -
  155. position: right
  156. type: sonata.block.service.text
  157. settings:
  158. content: >
  159. <h2>Welcome to the Sonata Admin</h2>
  160. <p>This is a <code>sonata.block.service.text</code> from the Block
  161. Bundle, you can create and add new block in these area by configuring
  162. the <code>sonata_admin</code> section.</p> <br /> For instance, here
  163. a RSS feed parser (<code>sonata.block.service.rss</code>):
  164. -
  165. position: right
  166. type: sonata.block.service.rss
  167. settings:
  168. title: Sonata Project's Feeds
  169. url: http://sonata-project.org/blog/archive.rss
  170. .. note::
  171. Blocks may accept/require additional settings to be passed in order to
  172. work properly. Refer to the associated documentation/implementation to
  173. get more information on each block's options and requirements.
  174. Display two ``Admin`` list blocks with different dashboard groups
  175. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  176. The same block can have multiple instances, and be displayed multiple times
  177. across the Dashboard using different configuration settings for each instance.
  178. A particular example is the ``Admin`` list block, which can be configured to
  179. suit this scenario.
  180. .. code-block:: yaml
  181. # app/config/config.yml
  182. sonata_admin:
  183. dashboard:
  184. blocks:
  185. # display two dashboard blocks
  186. -
  187. position: left
  188. type: sonata.admin.block.admin_list
  189. settings:
  190. groups: [sonata_page1, sonata_page2]
  191. -
  192. position: right
  193. type: sonata.admin.block.admin_list
  194. settings:
  195. groups: [sonata_page3]
  196. groups:
  197. sonata_page1:
  198. items:
  199. - sonata.page.admin.myitem1
  200. sonata_page2:
  201. items:
  202. - sonata.page.admin.myitem2
  203. - sonata.page.admin.myitem3
  204. sonata_page3:
  205. items:
  206. - sonata.page.admin.myitem4
  207. In this example, you would have two ``admin_list`` blocks on your dashboard, each
  208. of them containing just the respectively configured groups.
  209. .. _`SonataBlock documentation page`: http://sonata-project.org/bundles/block/master/doc/index.html