From 233694ef12a9e0d30c52b1654cb1f54706a80ae0 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Thu, 2 May 2024 15:05:35 +0200
Subject: [PATCH] display skip links for first and second navigagion layer only
 when there are elements

---
 lib/classes/sidebar/Sidebar.php | 4 ++--
 templates/header.php            | 8 ++++++--
 templates/tabs.php              | 4 ++--
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/classes/sidebar/Sidebar.php b/lib/classes/sidebar/Sidebar.php
index 65fc62d896e..ba1e609d2c1 100644
--- a/lib/classes/sidebar/Sidebar.php
+++ b/lib/classes/sidebar/Sidebar.php
@@ -186,7 +186,7 @@ class Sidebar extends WidgetContainer
         static $actions_widget_added = false;
 
 
-        if ($widget instanceof NavigationWidget && !$navigation_widget_added) {
+        if ($widget instanceof NavigationWidget && !$navigation_widget_added && $widget->hasElements()) {
             SkipLinks::addIndex(
                 _('Dritte Navigationsebene'),
                 $widget->getId(),
@@ -197,7 +197,7 @@ class Sidebar extends WidgetContainer
             $navigation_widget_added = true;
         }
 
-        if ($widget instanceof ActionsWidget && !$actions_widget_added) {
+        if ($widget instanceof ActionsWidget && !$actions_widget_added && $widget->hasElements()) {
             if (!$widget->getId()) {
                 $widget->setId('sidebar-actions');
             }
diff --git a/templates/header.php b/templates/header.php
index b8750389556..711d51785d2 100644
--- a/templates/header.php
+++ b/templates/header.php
@@ -216,7 +216,9 @@ if ($navigation) {
 
     <!-- Main navigation and right-hand logo -->
     <nav id="navigation-level-1" aria-label="<?= _('Hauptnavigation') ?>">
-        <? SkipLinks::addIndex(_('Hauptnavigation'), 'navigation-level-1', 2, false); ?>
+        <? if (!empty($header_nav['visible'])) : ?>
+            <? SkipLinks::addIndex(_('Hauptnavigation'), 'navigation-level-1', 2, false) ?>
+        <? endif ?>
         <ul id="navigation-level-1-items" <? if (count($header_nav['hidden']) > 0) echo 'class="overflown"'; ?>>
         <? foreach ($header_nav['visible'] as $path => $nav): ?>
             <?= $this->render_partial(
@@ -297,10 +299,12 @@ if ($navigation) {
                 </div>
             <? endif ?>
 
-            <? SkipLinks::addIndex(_('Zweite Navigationsebene'), 'navigation-level-2', 910) ?>
             <nav id="navigation-level-2" aria-label="<?= _('Zweite Navigationsebene') ?>">
 
                 <? if (PageLayout::isHeaderEnabled() /*&& isset($navigation)*/) : ?>
+                    <? if (!empty($navigation)) : ?>
+                        <? SkipLinks::addIndex(_('Zweite Navigationsebene'), 'navigation-level-2', 910) ?>
+                    <? endif ?>
                     <?= $this->render_partial('tabs', compact('navigation')) ?>
                 <? endif; ?>
             </nav>
diff --git a/templates/tabs.php b/templates/tabs.php
index 987e0fd1b16..24597cb4e95 100644
--- a/templates/tabs.php
+++ b/templates/tabs.php
@@ -7,10 +7,10 @@ foreach (Navigation::getItem("/")->getSubNavigation() as $path => $nav) {
 }
 ?>
 <div class="tabs_wrapper">
-    <? SkipLinks::addIndex(_('Zweite Navigationsebene'), 'navigation-level-2', 10, false); ?>
     <ul id="tabs">
         <? if (!empty($navigation)): ?>
-        <? foreach ($navigation as $path => $nav) : ?>
+            <? SkipLinks::addIndex(_('Zweite Navigationsebene'), 'navigation-level-2', 10, false); ?>
+            <? foreach ($navigation as $path => $nav) : ?>
             <? if ($nav->isVisible()) : ?>
                 <li id="nav_<?= $path1 ?? '' ?>_<?= $path ?>"<?= $nav->isActive() ? ' class="current"' : '' ?>>
                     <? if ($nav->isEnabled()): ?>
-- 
GitLab