Skip to content

Commit 96922d7

Browse files
Merge pull request #18844 from MauricioFauth/top-menu-refactor
Merge top_menu and breadcrumbs templates
2 parents 4d51943 + 5eaced9 commit 96922d7

3 files changed

Lines changed: 40 additions & 45 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,26 @@
4242
{% endif %}
4343
</ol>
4444
</nav>
45+
46+
<div id="topmenucontainer" class="menucontainer">
47+
<nav class="navbar navbar-expand-lg">
48+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-label="
49+
{%- trans %}Toggle navigation{% notes %}Show or hide the menu using the hamburger style button{% endtrans %}" aria-controls="navbarNav" aria-expanded="false">
50+
<span class="navbar-toggler-icon"></span>
51+
</button>
52+
<div class="collapse navbar-collapse" id="navbarNav">
53+
<ul id="topmenu" class="navbar-nav">
54+
{% for tab in tabs %}
55+
<li class="nav-item{{ tab.active ? ' active' }}">
56+
<a class="nav-link text-nowrap disableAjax" href="{{ url(tab.route, url_params|merge(tab.args ?? [])) }}">
57+
{{ get_icon(tab.icon, tab.text, false, true, 'TabsMode') }}
58+
{% if tab.active %}
59+
<span class="visually-hidden">{% trans %}(current){% notes %}Current page{% endtrans %}</span>
60+
{% endif %}
61+
</a>
62+
</li>
63+
{% endfor %}
64+
</ul>
65+
</div>
66+
</nav>
67+
</div>

resources/templates/top_menu.twig

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Menu.php

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ public function __construct(
5050
*/
5151
public function getDisplay(): string
5252
{
53-
$retval = $this->getBreadcrumbs();
54-
$retval .= $this->getMenu();
55-
56-
return $retval;
53+
$breadcrumbs = $this->getBreadcrumbs();
54+
$menu = $this->getMenu();
55+
56+
return $this->template->render('menu/main', [
57+
'server' => $breadcrumbs['server'],
58+
'database' => $breadcrumbs['database'],
59+
'table' => $breadcrumbs['table'],
60+
'tabs' => $menu['tabs'],
61+
'url_params' => $menu['url_params'],
62+
]);
5763
}
5864

59-
/**
60-
* Returns the menu as HTML
61-
*
62-
* @return string HTML formatted menubar
63-
*/
64-
private function getMenu(): string
65+
/** @return array{tabs: mixed[], url_params: mixed[]} */
66+
private function getMenu(): array
6567
{
6668
$urlParams = [];
6769

@@ -84,7 +86,7 @@ private function getMenu(): string
8486
// Filter out any tabs that are not allowed
8587
$tabs = array_intersect_key($tabs, $allowedTabs);
8688

87-
return $this->template->render('top_menu', ['tabs' => $tabs, 'url_params' => $urlParams]);
89+
return ['tabs' => $tabs, 'url_params' => $urlParams];
8890
}
8991

9092
/**
@@ -135,12 +137,8 @@ private function getAllowedTabs(string $level): array
135137
return $allowedTabs;
136138
}
137139

138-
/**
139-
* Returns the breadcrumbs as HTML
140-
*
141-
* @return string HTML formatted breadcrumbs
142-
*/
143-
private function getBreadcrumbs(): string
140+
/** @return array{server: mixed[], database: mixed[], table: mixed[]} */
141+
private function getBreadcrumbs(): array
144142
{
145143
$server = [];
146144
$database = [];
@@ -171,7 +169,7 @@ private function getBreadcrumbs(): string
171169
}
172170

173171
if (mb_strstr($table['comment'], '; InnoDB free')) {
174-
$table['comment'] = preg_replace('@; InnoDB free:.*?$@', '', $table['comment']);
172+
$table['comment'] = (string) preg_replace('@; InnoDB free:.*?$@', '', $table['comment']);
175173
}
176174
} else {
177175
// no table selected, display database comment if present
@@ -185,11 +183,7 @@ private function getBreadcrumbs(): string
185183
}
186184
}
187185

188-
return $this->template->render('menu/breadcrumbs', [
189-
'server' => $server,
190-
'database' => $database,
191-
'table' => $table,
192-
]);
186+
return ['server' => $server, 'database' => $database, 'table' => $table];
193187
}
194188

195189
/**

0 commit comments

Comments
 (0)