site_nav.html.twig 9.31 KB
Newer Older
1 2 3
{% block site_nav %}
  {% set active %}{% block site_nav_active '' %}{% endset %}
  <nav class="site-nav">
Emma's avatar
Emma committed
4
    <div class="site-nav__container content-container">
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
      {{ block('site_nav_header') }}
      {{ block('site_nav_main_menu') }}
      {{ block('site_nav_search') }}
      {{ block('site_nav_user_menu') }}
    </div>
  </nav>
{% endblock site_nav %}

{% block site_nav_header %}
  {% from '_macros/icon.html.twig' import icon %}
  <header class="site-nav__header">
    <a href="{{ path('front') }}"
       class="no-underline site-nav__link {{ active == 'front' ? 'site-nav__link--active' }}"
       aria-label="{{ 'nav.home'|trans }}">
      {{ icon('home', 'nav.home'|trans, 'icon--no-align no-desktop') }}
      <b class="no-mobile no-underline__exempt">{{ site_name() }}</b>
    </a>
  </header>
{% endblock site_nav_header %}

{% block site_nav_main_menu %}
  {% from '_macros/icon.html.twig' import icon %}
  {% set active_menu_item %}{% block site_nav_main_menu_active '' %}{% endset %}

  <div class="site-nav__main-menu-container site-nav__mobile-hidden dropdown dropdown--mobile-only">
    <button type="button"
            class="site-nav__link {{ (active == 'places' or active == 'admin') ? 'site-nav__link--active' }} site-nav__mobile-toggle no-desktop dropdown__toggle unbuttonize"
            aria-label="{{ 'nav.places'|trans }}">
      {{- icon('menu', 'nav.places'|trans, 'icon--no-align') -}}
    </button>

    <ul class="site-nav__menu site-nav__main-menu unlistify dropdown__menu">
      {{ block('site_nav_main_menu_items') }}
    </ul>
  </div>
{% endblock site_nav_main_menu %}

{% block site_nav_main_menu_items %}
  {% from '_macros/icon.html.twig' import icon %}
  <li>
    <a href="{{ path('forum_list') }}"
       class="site-nav__link {{ active_menu_item == 'forums' ? 'site-nav__link--active' }}">
      {{- 'nav.forums'|trans -}}
    </a>
  </li>

  <li>
    <a href="{{ path('wiki') }}"
       class="site-nav__link {{ active_menu_item == 'wiki' ? 'site-nav__link--active' }}">
      {{- 'nav.wiki'|trans -}}
    </a>
  </li>

  {% if is_granted('ROLE_ADMIN') %}
    <li class="dropdown">
      <button type="button"
              class="dropdown__toggle no-underline no-wrap site-nav__link unbuttonize {{ active == 'admin' ? 'site-nav__link--active' }}">
        <span class="no-underline__exempt">{{ 'label.admin'|trans }}</span>
        <span class="dropdown__arrow" aria-hidden="true"></span>
      </button>
Emma's avatar
Emma committed
65
      <ul class="dropdown-card dropdown__menu no-wrap unlistify">
66 67 68 69 70 71 72 73 74
        {{ block('site_nav_main_menu_admin_items') }}
      </ul>
    </li>
  {% endif %}
{% endblock site_nav_main_menu_items %}

{% block site_nav_main_menu_admin_items %}
  {% from '_macros/icon.html.twig' import icon %}
  <li>
75
    <a href="{{ path('user_bans') }}" class="menu-item {{ active_menu_item == 'bans' ? 'menu-item--active' }}">
76 77 78 79 80
      {{ icon('hammer') }}
      {{ 'label.bans'|trans }}
    </a>
  </li>
  <li>
81
    <a href="{{ path('manage_forum_categories') }}" class="menu-item {{ active_menu_item == 'forum_categories' ? 'menu-item--active' }}">
82 83 84 85 86
      {{ icon('sitemap') }}
      {{ 'nav.forum_categories'|trans }}
    </a>
  </li>
  <li>
87
    <a href="{{ path('users') }}" class="menu-item {{ active_menu_item == 'users' ? 'menu-item--active' }}">
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
      {{ icon('user') }}
      {{ 'nav.users'|trans }}
    </a>
  </li>
{% endblock site_nav_main_menu_admin_items %}

{% block site_nav_search %}
  {% from '_macros/icon.html.twig' import icon %}
  {% set search_query = app.request.query.get('q') %}
  {% if active != 'search' or search_query is iterable %}
    {% set search_query = null %}
  {% endif %}
  <form action="{{ path('search') }}" class="site-nav__mobile-hidden site-nav__search dropdown dropdown--mobile-only">
    <button type="button"
            class="site-nav__link {{ active == 'search' ? 'site-nav__link--active' }} site-nav__mobile-toggle no-desktop dropdown__toggle unbuttonize"
            aria-label="{{ 'nav.search'|trans }}">
      {{- icon('search', 'nav.search'|trans, 'icon--no-align') -}}
    </button>

    <div class="site-nav__search-row dropdown__menu">
      <label class="site-nav__search-label" for="site-nav-search" aria-hidden="true">
        {{ icon('search', '', 'icon--no-align') }}
      </label>
      <input name="q"
             type="search"
             class="form-control site-nav__search-input"
             id="site-nav-search"
             value="{{ search_query }}"
             aria-label="{{ 'label.search_query'|trans }}">
    </div>
  </form>
{% endblock site_nav_search %}

{% block site_nav_user_menu %}
  <ul class="site-nav__menu site-nav__user-menu unlistify">
    {% if not is_granted('ROLE_USER') %}
      {{ block('site_nav_user_menu_logged_out') }}
    {% else %}
      {{ block('site_nav_user_menu_logged_in') }}
    {% endif %}
  </ul>
{% endblock site_nav_user_menu %}

{% block site_nav_user_menu_logged_out %}
  <li>
    <a href="{{ path('login') }}" class="site-nav__link {{ active == 'login' ? 'site-nav__link--active' }}">
      {{- 'nav.log_in'|trans -}}
    </a>
  </li>
  <li>
    <a href="{{ path('registration') }}" class="site-nav__link {{ active == 'registration' ? 'site-nav__link--active' }}">
      {{- 'nav.register'|trans -}}
    </a>
  </li>
{% endblock site_nav_user_menu_logged_out %}

{% block site_nav_user_menu_logged_in %}
  {% from '_macros/icon.html.twig' import icon %}
  {% set notification_count = is_granted('ROLE_USER') ? app.user.notifications|length : 0 %}
  {% set active_menu_item %}{% if active == 'user' %}{% block site_nav_user_menu_active '' %}{% endif %}{% endset %}
  <li>
    <a href="{{ path('notifications') }}"
       class="no-underline no-wrap site-nav__link
             {{ notification_count > 0 ? 'site-nav__has-notifications' }}
             {{ active == 'notifications' ? 'site-nav__link--active' }}"
       title="{{ 'nav.notifications_count'|trans({'%count%': notification_count|localizednumber}) }}"
       aria-label="{{ 'nav.notifications_count'|trans({'%count%': notification_count|localizednumber}) }}">
      {% if notification_count > 0 %}
        {{ icon('envelope-open', 'nav.notifications'|trans, 'icon--no-align') }}
        <small class="no-underline__exempt" aria-hidden="true">{{ notification_count|localizednumber }}</small>
      {% else %}
        {{ icon('envelope', 'nav.notifications'|trans, 'icon--no-align') }}
      {% endif %}
    </a>
  </li>

  <li>
    <a href="{{ path('submit', { forum_name: forum.name ?? null }) }}"
       class="no-underline no-wrap site-nav__link {{ active == 'submit' ? 'site-nav__link--active' }}"
       aria-label="{{ 'nav.submit'|trans }}">
      {{ icon('plus', 'nav.submit'|trans, 'icon--no-align', 'no-desktop') }}
      <span class="no-underline__exempt no-mobile">{{ 'nav.submit'|trans }}</span>
    </a>
  </li>

  <li class="dropdown dropdown--right">
    <button type="button" class="dropdown__toggle no-underline site-nav__link no-wrap unbuttonize {{ active == 'user' ? 'site-nav__link--active' }}">
      {{ icon('user', 'nav.user'|trans, 'icon--no-align', 'no-desktop') }}
      <strong class="no-underline__exempt no-mobile">{{ app.user.username }}</strong>
      <span class="dropdown__arrow no-mobile" aria-hidden="true"></span>
    </button>

Emma's avatar
Emma committed
180
    <ul class="dropdown-card dropdown__menu unlistify no-wrap">
181 182 183 184 185 186 187
      {{ block('site_nav_user_menu_dropdown_items') }}
    </ul>
  </li>
{% endblock site_nav_user_menu_logged_in %}

{% block site_nav_user_menu_dropdown_items %}
  {% from '_macros/icon.html.twig' import icon %}
188 189 190 191 192 193 194 195
  <li class="no-desktop">
    <span class="menu-item ">
      {{ 'nav.logged_in_as_user'|trans({
        '%user%': '<strong>%s</strong>'|format(app.user.username|e)
      })|raw }}
    </span>
  </li>
  <li class="no-desktop"><hr></li>
196 197
  <li>
    <a href="{{ path('user', {username: app.user.username}) }}"
198
       class="menu-item {{ active_menu_item == 'profile' ? 'menu-item--active' }}">
199 200 201 202 203 204
      {{ icon('user') }}
      {{ 'nav.profile'|trans }}
    </a>
  </li>
  <li>
    <a href="{{ path('edit_user', {username: app.user.username}) }}"
205
       class="menu-item {{ active_menu_item == 'account' ? 'menu-item--active' }}">
206 207 208 209 210 211
      {{ icon('lock') }}
      {{ 'nav.my_account'|trans }}
    </a>
  </li>
  <li>
    <a href="{{ path('user_settings', {username: app.user.username}) }}"
212
       class="menu-item {{ active_menu_item == 'preferences' ? 'menu-item--active' }}">
213 214 215 216 217 218
       {{ icon('settings') }}
       {{ 'nav.user_settings'|trans }}
    </a>
  </li>
  <li>
    <a href="{{ path('user_block_list', {username: app.user.username}) }}"
219
       class="menu-item {{ active_menu_item == 'block_list' ? 'menu-item--active' }}">
220 221 222 223
      {{ icon('block') }}
      {{ 'nav.block_list'|trans }}
    </a>
  </li>
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
  <li><hr></li>
  <li>
    <form action="{{ app.user.nightMode ? path('night_mode_off') : path('night_mode_on') }}" method="POST">
      <input type="hidden" name="token" value="{{ csrf_token('toggle_night_mode') }}">
      <button class="menu-item unbuttonize">
        {% if not app.user.nightMode %}
          {{ icon('moon-inv') }}
          {{ 'nav.dark_mode'|trans }}
        {%- else -%}
          {{ icon('sun-inv') }}
          {{ 'nav.light_mode'|trans }}
        {%- endif -%}
      </button>
    </form>
  </li>
239 240
  <li>
    <form action="{{ logout_path() }}" method="POST">
241
      <button class="menu-item unbuttonize">
242 243 244 245 246 247
        {{ icon('logout') }}
        {{ 'nav.log_out'|trans }}
      </button>
    </form>
  </li>
{% endblock site_nav_user_menu_dropdown_items %}