diff --git a/lib/classes/navigation/output/primary.php b/lib/classes/navigation/output/primary.php index b03e528f102..a30fff77dbb 100644 --- a/lib/classes/navigation/output/primary.php +++ b/lib/classes/navigation/output/primary.php @@ -58,8 +58,8 @@ class primary implements renderable, templatable { return [ 'primary' => $this->get_primary_nav(), 'custom' => $this->get_custom_menu($output), - 'lang' => $this->get_lang_menu($output), - 'user' => $this->get_user_menu(), + 'lang' => !isloggedin() || isguestuser() ? $this->get_lang_menu($output) : [], + 'user' => $this->get_user_menu($output), ]; } @@ -131,6 +131,7 @@ class primary implements renderable, templatable { $node = [ 'title' => $langname, 'text' => $langname, + 'link' => true, 'isactive' => $isactive, 'url' => $isactive ? new \moodle_url('#') : new \moodle_url($this->page->url, ['lang' => $langtype]), ]; @@ -143,15 +144,18 @@ class primary implements renderable, templatable { /** * Get/Generate the user menu. + * * This is leveraging the data from user_get_user_navigation_info and the logic in $OUTPUT->user_menu() * + * @param renderer_base $output * @return array */ - public function get_user_menu(): array { + public function get_user_menu(renderer_base $output): array { global $CFG, $USER, $PAGE; require_once($CFG->dirroot . '/user/lib.php'); $usermenudata = []; + $submenusdata = []; $info = user_get_user_navigation_info($USER, $PAGE); if (isset($info->unauthenticateduser)) { $info->unauthenticateduser['content'] = get_string($info->unauthenticateduser['content']); @@ -214,10 +218,45 @@ class primary implements renderable, templatable { return $value; }, $info->navitems); + // Include the language menu as a submenu within the user menu. + $langmenu = $this->get_lang_menu($output); + if (!empty($langmenu)) { + $languageitems = $langmenu['items']; + // If there are available languages, generate the data for the the language selector submenu. + if (!empty($languageitems)) { + $langsubmenuid = uniqid(); + // Generate the data for the link to language selector submenu. + $language = (object) [ + 'itemtype' => 'submenu-link', + 'submenuid' => $langsubmenuid, + 'title' => get_string('language'), + 'pixicon' => 'i/language', + 'divider' => false, + 'submenulink' => true, + ]; + + // Place the link before the 'Log out' menu item which is either the last item in the menu or + // second to last when 'Switch roles' is available. + $menuposition = count($modifiedarray) - 1; + if (has_capability('moodle/role:switchroles', $PAGE->context)) { + $menuposition = count($modifiedarray) - 2; + } + array_splice($modifiedarray, $menuposition, 0, [$language]); + + // Generate the data for the language selector submenu. + $submenusdata[] = (object)[ + 'id' => $langsubmenuid, + 'title' => get_string('languageselector'), + 'items' => $languageitems, + ]; + } + } + // Add dividers after the first item and before the last item. $modifiedarray[0]->divider = true; - $modifiedarray[count($info->navitems) - 2]->divider = true; + $modifiedarray[count($modifiedarray) - 2]->divider = true; $usermenudata['items'] = $modifiedarray; + $usermenudata['submenus'] = array_values($submenusdata); return $usermenudata; } diff --git a/lib/classes/output/icon_system_fontawesome.php b/lib/classes/output/icon_system_fontawesome.php index b35e5984e77..29d7f954b4d 100644 --- a/lib/classes/output/icon_system_fontawesome.php +++ b/lib/classes/output/icon_system_fontawesome.php @@ -345,6 +345,7 @@ class icon_system_fontawesome extends icon_system_font { 'core:i/warning' => 'fa-exclamation text-warning', 'core:i/window_close' => 'fa-window-close', 'core:i/withsubcat' => 'fa-plus-square', + 'core:i/language' => 'fa-language', 'core:m/USD' => 'fa-usd', 'core:t/addcontact' => 'fa-address-card', 'core:t/add' => 'fa-plus', diff --git a/theme/boost/layout/columns2.php b/theme/boost/layout/columns2.php index 0ce0dd41a60..56e1c5cdd46 100644 --- a/theme/boost/layout/columns2.php +++ b/theme/boost/layout/columns2.php @@ -65,6 +65,7 @@ $templatecontext = [ 'hasregionmainsettingsmenu' => !empty($regionmainsettingsmenu), 'primarymoremenu' => $OUTPUT->more_menu(array_merge($primarymenu['primary'], $primarymenu['custom']), 'navbar-nav'), 'secondarymoremenu' => $secondarynavigation, + 'usermenu' => $primarymenu['user'], ]; $nav = $PAGE->flatnav; $templatecontext['flatnavigation'] = $nav; diff --git a/theme/boost/templates/navbar.mustache b/theme/boost/templates/navbar.mustache index 70e10705ab1..d3c43f101d7 100644 --- a/theme/boost/templates/navbar.mustache +++ b/theme/boost/templates/navbar.mustache @@ -65,7 +65,9 @@ {{{ output.search_box }}} {{{ output.navbar_plugin_output }}}
- {{{ output.user_menu }}} + {{#usermenu}} + {{> core/user_menu }} + {{/usermenu}}