diff --git a/lib/classes/sidebar/Sidebar.php b/lib/classes/sidebar/Sidebar.php index a3479be0aec2195dcd2dbb3dfa2e9e5ee0bf48cb..d91578654cfc61a3b531ff6036817794bca4bb99 100644 --- a/lib/classes/sidebar/Sidebar.php +++ b/lib/classes/sidebar/Sidebar.php @@ -8,6 +8,13 @@ */ class Sidebar extends WidgetContainer { + /** + * Contains an optional image for the container. + */ + protected $image = false; + protected $title = false; + protected $context_avatar = null; + /** * Constructor, tries to automagically set the sidebar's title. */ @@ -18,13 +25,6 @@ class Sidebar extends WidgetContainer $this->setTitle(); } - /** - * Contains an optional image for the container. - */ - protected $image = false; - protected $title = false; - protected $context_avatar = null; - /** * Set an image for the sidebar. * @@ -162,6 +162,7 @@ class Sidebar extends WidgetContainer if ($this->hasWidgets()) { $template->widgets = $this->widgets; + array_walk($template->widgets, [$this, 'setupSkipLinks']); } else { $template->widgets = []; } @@ -209,4 +210,39 @@ class Sidebar extends WidgetContainer } return $breadcrumbs; } + + /** + * Inspects a widget and will set appropriate skiplinks. + * + * @param Widget $widget + */ + protected function setupSkipLinks(Widget $widget): void + { + static $navigation_widget_added = false; + static $actions_widget_added = false; + + + if ($widget instanceof NavigationWidget && !$navigation_widget_added) { + SkipLinks::addIndex( + _('Dritte Navigationsebene'), + $widget->getId(), + 20 + ); + + $navigation_widget_added = true; + } + + if ($widget instanceof ActionsWidget && !$actions_widget_added) { + if (!$widget->getId()) { + $widget->setId('sidebar-actions'); + } + SkipLinks::addIndex( + _('Aktionen'), + $widget->getId(), + 21 + ); + + $actions_widget_added = true; + } + } } diff --git a/templates/layouts/base.php b/templates/layouts/base.php index 52b709bda71048d6e37ec40fda718c61fc841a16..6fde8c93ccc6b6b6563b5dbbcb58cfd3d2368fbf 100644 --- a/templates/layouts/base.php +++ b/templates/layouts/base.php @@ -6,7 +6,7 @@ if ($navigation) { $subnavigation = $navigation->activeSubNavigation(); if ($subnavigation !== null) { $nav_links = new NavigationWidget(); - $nav_links->id = 'sidebar-navigation'; + $nav_links->setId('sidebar-navigation'); if (!$navigation->getImage()) { $nav_links->addLayoutCSSClass('show'); } diff --git a/templates/sidebar/sidebar.php b/templates/sidebar/sidebar.php index 6c40e57ecdaf55d069308e9c7c77460104f80571..a624596e296a5c272c3924a27163783026f71611 100644 --- a/templates/sidebar/sidebar.php +++ b/templates/sidebar/sidebar.php @@ -20,15 +20,6 @@ </div> <? foreach ($widgets as $index => $widget): ?> - <? - if ($widget instanceof NavigationWidget) { - $widget->setId('nav_layer_3'); - SkipLinks::addIndex(_('Dritte Navigationsebene'), 'nav_layer_3', 20, false); - } elseif ($widget instanceof ActionsWidget) { - $widget->setId('sidebar_actions'); - SkipLinks::addIndex(_('Aktionen'), 'sidebar_actions', 21, false); - } - ?> <?= $widget->render(['base_class' => 'sidebar']) ?> <? endforeach; ?> </section>