sonata_menu.html.twig 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. {% extends 'knp_menu.html.twig' %}
  2. {% block root %}
  3. {%- set listAttributes = item.childrenAttributes|merge({'class': 'sidebar-menu'}) %}
  4. {%- set request = item.extra('request') %}
  5. {{ block('list') -}}
  6. {% endblock %}
  7. {% block item %}
  8. {%- if item.displayed %}
  9. {#- check role of the group #}
  10. {%- set display = (item.extra('roles') is empty or is_granted('ROLE_SUPER_ADMIN') ) %}
  11. {%- for role in item.extra('roles') if not display %}
  12. {%- set display = is_granted(role) %}
  13. {%- endfor %}
  14. {%- endif %}
  15. {%- if item.displayed and display|default %}
  16. {%- set active = false %}
  17. {%- if item.extra('active') is not empty and item.extra('active') %}
  18. {%- set active = true %}
  19. {%- elseif item.extra('admin') is not empty and item.extra('admin').hasroute('list') and item.extra('admin').isGranted('LIST') and request.get('_sonata_admin') == item.extra('admin').code %}
  20. {%- set active = true %}
  21. {%- elseif item.route is defined and request.get('_route') == item.route %}
  22. {%- set active = true %}
  23. {%- else %}
  24. {%- for child in item.children if not active %}
  25. {%- if child.extra('admin') is not empty and child.extra('admin').hasroute('list') and child.extra('admin').isGranted('LIST') and request.get('_sonata_admin') == child.extra('admin').code %}
  26. {%- set active = true %}
  27. {%- elseif child.route is defined and request.get('_route') == child.route %}
  28. {%- set active = true %}
  29. {%- endif %}
  30. {%- endfor %}
  31. {%- endif %}
  32. {%- if item.hasChildren %}
  33. {%- do item.setAttribute('class', (item.attribute('class')~' treeview')|trim) %}
  34. {%- endif %}
  35. {%- if active %}
  36. {%- do item.setAttribute('class', (item.attribute('class')~' active')|trim) %}
  37. {%- do item.setChildrenAttribute('class', (item.childrenAttribute('class')~' active')|trim) %}
  38. {%- endif %}
  39. {%- do item.setChildrenAttribute('class', (item.childrenAttribute('class')~' treeview-menu')|trim) %}
  40. {{ parent() }}
  41. {% endif %}
  42. {% endblock %}
  43. {% block linkElement %}
  44. {% spaceless %}
  45. {% set translation_domain = item.extra('translation_domain', 'messages') %}
  46. {% set icon = item.attribute('icon')|default(item.level > 1 ? '<i class="fa fa-angle-double-right"></i>' : '') %}
  47. {% set is_link = true %}
  48. {{ parent() }}
  49. {% endspaceless %}
  50. {% endblock %}
  51. {% block spanElement %}
  52. {% spaceless %}
  53. <a href="#">
  54. {% set translation_domain = item.attribute('label_catalogue') %}
  55. {% set icon = item.attribute('icon')|default('') %}
  56. {{ parent() }}
  57. <i class="fa pull-right fa-angle-left"></i>
  58. </a>
  59. {% endspaceless %}
  60. {% endblock %}
  61. {% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans({}, translation_domain|default('messages')) }}{% endif %}{% endblock %}