user_dashboard.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. .. index::
  2. single: Dashboard
  3. User Dashboard
  4. ==============
  5. ``SonataUserBundle`` provides an easy way to customize the user portal (reachable through the /profile URL).
  6. Here's a preview:
  7. .. figure:: ../images/profile_dashboard.png
  8. :align: center
  9. :alt: The user profile dashboard
  10. :width: 700px
  11. Configuration
  12. -------------
  13. The default menu offers profile edition & user password forms.
  14. Would you like to customize this menu ? you can do so in the `sonata_user` configuration:
  15. .. code-block:: yaml
  16. sonata_user:
  17. profile:
  18. # Profile show page is a dashboard as in SonataAdminBundle
  19. dashboard:
  20. blocks:
  21. - { position: left, type: sonata.block.service.text, settings: { content: "<h2>Welcome!</h2> This is a sample user profile dashboard, feel free to override it in the configuration! Want to make this text dynamic? For instance display the user's name? Create a dedicated block and edit the configuration!"} }
  22. - { position: left, type: sonata.order.block.recent_orders, settings: { title: Recent Orders, number: 5, mode: public }}
  23. - { position: right, type: sonata.timeline.block.timeline, settings: { max_per_page: 15 }}
  24. - { position: right, type: sonata.news.block.recent_posts, settings: { title: Recent Posts, number: 5, mode: public }}
  25. - { position: right, type: sonata.news.block.recent_comments, settings: { title: Recent Comments, number: 5, mode: public }}
  26. # Customize user portal menu by setting links
  27. menu:
  28. - { route: 'sonata_user_profile_show', label: 'sonata_profile_title', domain: 'SonataUserBundle'}
  29. - { route: 'sonata_user_profile_edit', label: 'link_edit_profile', domain: 'SonataUserBundle'}
  30. - { route: 'sonata_customer_addresses', label: 'link_list_addresses', domain: 'SonataCustomerBundle'}
  31. - { route: 'sonata_user_profile_edit_authentication', label: 'link_edit_authentication', domain: 'SonataUserBundle'}
  32. - { route: 'sonata_order_index', label: 'order_list', domain: 'SonataOrderBundle'}
  33. If you want to display the menu in your action's template, you should inherit the ``SonataUserBundle:Profile:action.html.twig`` template. There you can override the ``sonata_profile_title`` & ``sonata_profile_content`` blocks.
  34. Dashboard
  35. ---------
  36. The ``Profile:show`` page is a dashboard as in SonataAdminBundle (you may see the documentation `here <https://sonata-project.org/bundles/admin/master/doc/reference/dashboard.html>`_). You may specify the blocks you want there, their settings and their positions. By default a simple text is displayed, but it's up to you to put there whatever you want.
  37. In the sample configuration you may see above, we chose to put this text, plus the latest orders from the customer attached to the customer, the latest user's actions, latest posts & comments on the website.
  38. Block
  39. -----
  40. You also have the ability to customize the block responsible for displaying the menu with the following options:
  41. * ``menu_name``
  42. This takes a Knp menu name as the argument and will completely override the menu.
  43. * ``menu_class``
  44. The menu ``<ul>`` class(es); by default set to ``nav nav-list``.
  45. * ``current_class``
  46. The current ``<li>`` element class(es); by default set to ``active``.
  47. * ``first_class and last_class``
  48. The first and last ``<li>`` element class(es) in the menu ; by default empty.
  49. Menu Factory
  50. ------------
  51. The `ProfileMenuBuilder` class is responsible for creating the user menu. It offers two public methods:
  52. * ``createProfileMenu`` which generates a new ``ItemInterface`` instance
  53. * ``buildProfileMenu`` which configures an existing ``ItemInterface`` instance.
  54. The latter method throws an event once configured: ``sonata.user.profile.configure_menu`` of type ``ProfileMenuEvent`` which contains the configured ``ItemInterface`` instance, would you choose to override it.