Skip to content

Commit 6fb5f06

Browse files
committed
User Menu
1 parent d8f2582 commit 6fb5f06

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/WebApp/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ public function getLoginUri() {
258258
/**
259259
* returns an array of menu items.
260260
* @param string $id - denotes the ID of the menu to return, depends on the chosen layout. NULL usually means the main menu.
261+
* Bootstrap layouts will ask for the 'user' menu which can return profile page, change password page and others.
261262
*/
262263
public function getMenu($id = NULL) {
263264
return NULL;

src/WebApp/BootstrapTheme/DefaultLayout.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function renderNavbarToggler() {
6565

6666
protected function renderNavbarContent() {
6767
$rc = '<div id="navbar-content" class="collapse navbar-collapse">'.
68-
'<ul class="navbar-nav mr-auto">';
68+
'<ul class="navbar-nav mr-auto main-menu">';
6969
$menu = $this->app->getMenu();
7070
if (($menu != NULL) && is_array($menu)) {
7171
foreach ($menu AS $menuItem) {
@@ -75,15 +75,31 @@ protected function renderNavbarContent() {
7575
$rc .= '</ul>';
7676
$principal = $this->app->getPrincipal();
7777
if ($principal != NULL) {
78-
$rc .= '<span class="navbar-text align-middle">'.$principal->__toString().'<a class="px-2" href="?logout"><i class="fas fa-sign-out-alt fa-lg"></i></a></span>';
78+
$rc .= '<ul class="navbar-nav user-menu">';
79+
$userMenu = $this->app->getMenu('user');
80+
if ($userMenu == NULL) {
81+
$userMenu = array();
82+
$userItem = new \WebApp\Component\MenuItem($this, $principal->__toString(), '#');
83+
$userMenu[] = new \WebApp\Component\MenuItem($userItem, 'logout_label', '?logout');
84+
$userMenu = array($userItem);
85+
}
86+
if (($userMenu != NULL) && is_array($userMenu)) {
87+
//$userMenu[] = new \WebApp\Component\MenuItem($this, 'logout_label', '?logout');
88+
foreach ($userMenu AS $menuItem) {
89+
$rc .= $this->theme->renderComponent($menuItem);
90+
}
91+
92+
}
93+
//$rc .= '<span class="navbar-text align-middle">'.$principal->__toString().'<a class="px-2" href="?logout"><i class="fas fa-sign-out-alt fa-lg"></i></a></span>';
94+
$rc .= '</ul>';
7995
} else if ($this->app->getLoginUri() != NULL) {
8096
$uri = $this->app->request->uri;
8197
if ($this->app->request->path == $this->app->getLoginUri()) {
8298
$uri = $this->app->request->path;
8399
} else {
84100
$uri = $this->app->getLoginUri().'?return='.urlencode($this->app->request->uri);
85101
}
86-
$rc .= '<span class="navbar-text align-middle"><a class="px-2" href="'.$uri.'"><i class="fas fa-sign-in-alt fa-lg"></i></a></span>';
102+
$rc .= '<span class="navbar-text align-middle"><a class="px-2" href="'.$uri.'">'.I18N::_('login_label').'</a></span>';
87103
}
88104
$rc .= '</nav>';
89105
return $rc;

src/i18n.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
'de' => 'Dies ist der Standardtext des Web-Frameworks.',
1010
'en' => 'This is the default text of the web-framework modules.',
1111
),
12+
'login_label' => array(
13+
'de' => '<i class="fas fa-sign-in-alt fa-lg"></i> Anmelden',
14+
'en' => '<i class="fas fa-sign-in-alt fa-lg"></i> Login',
15+
),
16+
'logout_label' => array(
17+
'de' => '<i class="fas fa-sign-out-alt fa-lg"></i> Abmelden',
18+
'en' => '<i class="fas fa-sign-out-alt fa-lg"></i> Logout',
19+
),
1220
'login_title' => array(
1321
'de' => 'Anmelden',
1422
'en' => 'Login',

0 commit comments

Comments
 (0)