You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
3.7KB

  1. {% macro render_menu_item(item, translation_domain, active) %}
  2. {% if item.type == 'divider' %}
  3. {{ item.label|trans(domain = translation_domain) }}
  4. {% else %}
  5. {% set menu_params = { menuIndex: item.menu_index, submenuIndex: item.submenu_index } %}
  6. {% set path =
  7. item.type == 'link' ? item.url :
  8. item.type == 'route' ? path(item.route, item.params) :
  9. item.type == 'entity' ? path('easyadmin', { entity: item.entity, action: 'list' }|merge(menu_params)|merge(item.params)) :
  10. item.type == 'empty' ? '#' : ''
  11. %}
  12. {# if the URL generated for the route belongs to the backend, regenerate
  13. the URL to include the menu_params to display the selected menu item
  14. (this is checked comparing the beginning of the route URL with the backend homepage URL)
  15. #}
  16. {% if item.type == 'route' and (path starts with path('easyadmin')) %}
  17. {% set path = path(item.route, menu_params|merge(item.params)) %}
  18. {% endif %}
  19. <a href="{{ path }}"
  20. class="nav-link {{ item.css_class|default('') }} {{ active ? 'active' }}"
  21. {% if item.target|default(false) %}target="{{ item.target }}"{% endif %}
  22. {% if item.rel|default(false) %}rel="{{ item.rel }}"{% endif %}>
  23. {% if item.icon is not empty %}<i class="fa fa-fw {{ item.icon }}"></i>{% endif %}
  24. <p>{{ item.label|trans(domain = translation_domain) }}
  25. {% if item.children|default([]) is not empty %}<i class="right fas fa-angle-left"></i>{% endif %}
  26. </p>
  27. </a>
  28. {% endif %}
  29. {% endmacro %}
  30. {% import _self as helper %}
  31. {% block main_menu_before %}{% endblock %}
  32. {% set _translation_domain = (_entity_config.translation_domain)|default(easyadmin_config('translation_domain'))|default('messages') %}
  33. <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
  34. {% set _menu_items = easyadmin_config('design.menu') %}
  35. {% block main_menu %}
  36. {% for item in _menu_items %}
  37. {% block menu_item %}
  38. {% set is_selected_menu = app.request.query.get('menuIndex')|default(-1) == item.menu_index %}
  39. {% set is_selected_submenu = is_selected_menu and app.request.query.get('submenuIndex')|default(-1) != -1 %}
  40. {% if easyadmin_is_granted(item.permission) %}
  41. <li class="{{ item.type == 'divider' ? 'nav-header' : 'nav-item'}} {{ item.children is not empty ? 'treeview' }} {{ is_selected_menu ? 'menu-open' }}">
  42. {{ helper.render_menu_item(item, _translation_domain, is_selected_menu) }}
  43. {% if item.children|default([]) is not empty %}
  44. <ul class="nav nav-treeview">
  45. {% for subitem in item.children %}
  46. {% block menu_subitem %}
  47. {% if easyadmin_is_granted(subitem.permission) %}
  48. <li class="nav-item ">
  49. {{ helper.render_menu_item(subitem, _translation_domain, is_selected_menu and app.request.query.get('submenuIndex')|default(-1) == subitem.submenu_index ? true) }}
  50. </li>
  51. {% endif %}
  52. {% endblock menu_subitem %}
  53. {% endfor %}
  54. </ul>
  55. {% endif %}
  56. </li>
  57. {% endif %}
  58. {% endblock menu_item %}
  59. {% endfor %}
  60. {% endblock main_menu %}
  61. </ul>
  62. {% block main_menu_after %}{% endblock %}