Header/Footer items config: Add configurable permissions

This commit is contained in:
Igor Scheller 2023-12-24 14:08:41 +01:00 committed by xuwhite
parent 4fa99b8a04
commit 4244acfb4d
3 changed files with 31 additions and 13 deletions

View File

@ -32,14 +32,22 @@ return [
// Available link placeholders: %lang% // Available link placeholders: %lang%
// To disable a header_item in the config.php, you can set its value to null // To disable a header_item in the config.php, you can set its value to null
'header_items' => [ 'header_items' => [
//'Foo' => 'https://foo.bar/batz-%lang%.html', // 'Name' => 'URL',
// 'Name' => ['URL', 'permission'],
// Name can be a translation string, permission is a engelsystem privilege
//'Foo' => ['https://foo.bar/batz-%lang%.html', 'logout'], // Permission: for logged-in users
], ],
// Footer links // Footer links
// To disable a footer item in the config.php, you can set its value to null // To disable a footer item in the config.php, you can set its value to null
'footer_items' => [ 'footer_items' => [
// 'Name' => 'URL',
// 'Name' => ['URL', 'permission'],
// Name can be a translation string, permission is a engelsystem privilege
// URL to the angel faq and job description // URL to the angel faq and job description
'FAQ' => env('FAQ_URL', '/faq'), 'faq.faq' => [env('FAQ_URL', '/faq'), 'faq.view'],
// Contact email address, linked on every page // Contact email address, linked on every page
'Contact' => env('CONTACT_EMAIL', 'mailto:ticket@c3heaven.de'), 'Contact' => env('CONTACT_EMAIL', 'mailto:ticket@c3heaven.de'),

View File

@ -36,11 +36,15 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% for name,url in config('footer_items') %} {% for name,opt in config('footer_items') %}
<a href="{% if url starts with '/' %}{{ url(url) }}{% else %}{{ url }}{% endif %}"> {% set url = opt is iterable ? opt[0] : opt %}
{% if '@' in url %}{{ m.icon('envelope') }}{% endif %} {% set permission = opt is iterable ? opt[1] : null %}
{{ __(name) }} {% if not permission or has_permission_to(permission) %}
</a> · <a href="{% if url starts with '/' %}{{ url(url) }}{% else %}{{ url }}{% endif %}">
{% if '@' in url %}{{ m.icon('envelope') }}{% endif %}
{{ __(name) }}
</a> ·
{% endif %}
{% endfor %} {% endfor %}
<a href="https://github.com/engelsystem/engelsystem/issues">{{ __('footer.issues') }}</a> <a href="https://github.com/engelsystem/engelsystem/issues">{{ __('footer.issues') }}</a>
· <a href="https://github.com/engelsystem/engelsystem/">{{ __('footer.github') }}</a> · <a href="https://github.com/engelsystem/engelsystem/">{{ __('footer.github') }}</a>

View File

@ -45,12 +45,18 @@
{% if config('header_items') %} {% if config('header_items') %}
<ul class="navbar-nav mb-2 mb-lg-0"> <ul class="navbar-nav mb-2 mb-lg-0">
{% for text,link in config('header_items', {}) %} {% for name,opt in config('header_items', {}) %}
<li class="nav-item"> {% set url = opt is iterable ? opt[0] : opt %}
<a class="nav-link" href="{{ link|replace({'%lang%': session_get('locale')|split('_')[0]})|escape('html_attr') }}"> {% set permission = opt is iterable ? opt[1] : null %}
{{ text }} {% if not permission or has_permission_to(permission) %}
</a> <li class="nav-item">
</li> <a class="nav-link"
href="{{ url|replace({'%lang%': session_get('locale')|split('_')[0]})|escape('html_attr') }}"
>
{{ __(name) }}
</a>
</li>
{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}