Skip to content

Commit

Permalink
Refactor navbar items rendering (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
jskowronski39 authored Nov 28, 2024
2 parents 20c34af + 6cf1040 commit d3b40cb
Showing 1 changed file with 46 additions and 26 deletions.
72 changes: 46 additions & 26 deletions templates/shared/_partial/navbar/_navbar_links.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,28 @@
{{ 'Manage mods'|trans }}
</a>
<div class="dropdown-menu">
{% if is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::MOD_LIST').value) %}
<a class="dropdown-item" href="{{ path('app_mod_list') }}">{{ 'Mods'|trans }}</a>
{% endif %}

{% if is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::MOD_GROUP_LIST').value) %}
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ path('app_mod_group_list') }}">{{ 'Mod groups'|trans }}</a>
{% endif %}

{% if is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::DLC_LIST').value) %}
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ path('app_dlc_list') }}">{{ 'DLCs'|trans }}</a>
{% endif %}

{% if is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::MOD_LIST_LIST').value) %}
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ path('app_mod_list_list') }}">{{ 'Mod lists'|trans }}</a>
{% endif %}
{{ _self.navbar_dropdown([
{
'show': is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::MOD_LIST').value),
'url': path('app_mod_list'),
'label': 'Mods'|trans
},
{
'show': is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::MOD_GROUP_LIST').value),
'url': path('app_mod_group_list'),
'label': 'Mod groups'|trans
},
{
'show': is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::DLC_LIST').value),
'url': path('app_dlc_list'),
'label': 'DLCs'|trans
},
{
'show': is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::MOD_LIST_LIST').value),
'url': path('app_mod_list_list'),
'label': 'Mod lists'|trans
},
]) }}
</div>
</li>
{% endif %}
Expand All @@ -50,16 +54,32 @@
{{ 'Manage users'|trans }}
</a>
<div class="dropdown-menu">
{% if is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::USER_LIST').value) %}
<a class="dropdown-item" href="{{ path('app_user_list') }}">{{ 'Users'|trans }}</a>
{% endif %}

{% if is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::USER_GROUP_LIST').value) %}
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ path('app_user_group_list') }}">{{ 'User groups'|trans }}</a>
{% endif %}
{{ _self.navbar_dropdown([
{
'show': is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::USER_LIST').value),
'url': path('app_user_list'),
'label': 'Users'|trans
},
{
'show': is_granted(constant('App\\Shared\\Security\\Enum\\PermissionsEnum::USER_GROUP_LIST').value),
'url': path('app_user_group_list'),
'label': 'User groups'|trans
},
]) }}
</div>
</li>
{% endif %}
</ul>
<!-- Links -->

{% macro navbar_dropdown(links) %}
{% for link in links %}
{% if link.show == true %}
<a class="dropdown-item" href="{{ link.url }}">{{ link.label }}</a>

{% if loop.last == false %}
<div class="dropdown-divider"></div>
{% endif %}
{% endif %}
{% endfor %}
{% endmacro %}

0 comments on commit d3b40cb

Please sign in to comment.