MDL-72481 admin: Render the site admin navigation menu as tablist

only render the secondary nav as tablist if it is for the site admin tabs

Co-authored-by: Shamim Rezaie <shamim@moodle.com>
This commit is contained in:
Jun Pataleta 2022-02-18 15:55:31 +11:00 committed by Shamim Rezaie
parent 1f21daf8b3
commit 6937d87ddd
12 changed files with 36 additions and 16 deletions

View File

@ -11,6 +11,7 @@ $query = trim(optional_param('query', '', PARAM_NOTAGS)); // Search string
$context = context_system::instance();
$PAGE->set_context($context);
$PAGE->set_secondary_navigation(true, true);
$hassiteconfig = has_capability('moodle/site:config', $context);
@ -91,7 +92,7 @@ if ($showsettingslinks) {
if ($node) {
$secondarynavigation = false;
if ($PAGE->has_secondary_navigation()) {
$moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs');
$moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs', true, true);
$secondarynavigation = $moremenu->export_for_template($OUTPUT);
}
echo $OUTPUT->render_from_template('core/settings_link_page',

View File

@ -76,7 +76,7 @@ $PAGE->set_title($title);
$PAGE->requires->css($cssfile);
$jsonfile = new moodle_url('/admin/tool/componentlibrary/hugo/site/data/my-index.json');
$PAGE->requires->js_call_amd('tool_componentlibrary/loader', 'init', ['jsonfile' => $jsonfile->out()]);
$PAGE->has_secondary_navigation_setter(false);
$PAGE->set_secondary_navigation(false);
if (get_config('core', 'allowthemechangeonurl')) {
$themes = core_component::get_plugin_list('theme');

View File

@ -36,7 +36,7 @@ $PAGE->set_context($context);
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->navbar->add($title);
$PAGE->has_secondary_navigation_setter(false);
$PAGE->set_secondary_navigation(false);
// This allows the webserver to dictate wether the http status should remain
// what it would have been, or force it to be a 404. Under other conditions

View File

@ -103,10 +103,10 @@ $editing = $PAGE->user_is_editing();
$PAGE->set_title($SITE->fullname);
$PAGE->set_heading($SITE->fullname);
if (has_capability('moodle/course:update', context_system::instance())) {
$PAGE->has_secondary_navigation_setter(true);
$PAGE->set_secondary_navigation(true);
$PAGE->set_secondary_active_tab('coursehome');
} else {
$PAGE->has_secondary_navigation_setter(false);
$PAGE->set_secondary_navigation(false);
}
$courserenderer = $PAGE->get_renderer('core', 'course');

View File

@ -393,6 +393,11 @@ class moodle_page {
*/
protected $_hassecondarynavigation = true;
/**
* @var bool Should the secondary menu be rendered as a tablist as opposed to a menubar.
*/
protected $_hastablistsecondarynavigation = false;
/**
* @var string the key of the secondary node to be activated.
*/
@ -2213,10 +2218,13 @@ class moodle_page {
/**
* Set the flag to indicate if the secondary navigation should be rendered.
*
* @param bool $value If the secondary navigation should be rendered.
* @param bool $hassecondarynavigation If the secondary navigation should be rendered.
* @param bool $istablist When true, the navigation bar should be rendered and behave with a tablist ARIA role.
* If false, it's rendered with a menubar ARIA role. Defaults to false.
*/
public function has_secondary_navigation_setter(bool $value) : void {
$this->_hassecondarynavigation = $value;
public function set_secondary_navigation(bool $hassecondarynavigation, bool $istablist = false): void {
$this->_hassecondarynavigation = $hassecondarynavigation;
$this->_hastablistsecondarynavigation = $istablist;
}
/**
@ -2224,10 +2232,19 @@ class moodle_page {
*
* @return bool
*/
public function has_secondary_navigation() : bool {
public function has_secondary_navigation(): bool {
return $this->_hassecondarynavigation;
}
/**
* Check if the secondary navigation should be rendered with a tablist as opposed to a menubar.
*
* @return bool
*/
public function has_tablist_secondary_navigation(): bool {
return $this->_hastablistsecondarynavigation;
}
/**
* Set the key of the secondary nav node to be activated.
*

View File

@ -51,7 +51,7 @@ $PAGE->set_context($context);
$PAGE->set_url('/my/courses.php');
$PAGE->add_body_classes(['limitedwidth', 'page-mycourses']);
$PAGE->set_pagelayout('mycourses');
$PAGE->has_secondary_navigation_setter(false);
$PAGE->set_secondary_navigation(false);
$PAGE->set_pagetype('my-index');
$PAGE->blocks->add_region('content');

View File

@ -88,7 +88,7 @@ $PAGE->blocks->add_region('content');
$PAGE->set_subpage($currentpage->id);
$PAGE->set_title($pagetitle);
$PAGE->set_heading($pagetitle);
$PAGE->has_secondary_navigation_setter(false);
$PAGE->set_secondary_navigation(false);
if (!isguestuser()) { // Skip default home page for guests
if (get_home_page() != HOMEPAGE_MY) {

View File

@ -51,7 +51,7 @@ $PAGE->set_pagetype('my-index');
$PAGE->blocks->add_region('content');
$PAGE->set_title($pagetitle);
$PAGE->set_heading($pagetitle);
$PAGE->has_secondary_navigation_setter(false);
$PAGE->set_secondary_navigation(false);
$PAGE->set_primary_active_tab('myhome');
// If we are resetting all, just output a progress bar.

View File

@ -38,7 +38,8 @@ $hasblocks = (strpos($blockshtml, 'data-block=') !== false || !empty($addblockbu
$secondarynavigation = false;
$overflow = '';
if ($PAGE->has_secondary_navigation()) {
$moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs');
$tablistnav = $PAGE->has_tablist_secondary_navigation();
$moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs', true, $tablistnav);
$secondarynavigation = $moremenu->export_for_template($OUTPUT);
$overflowdata = $PAGE->secondarynav->get_overflow_menu_data();
if (!is_null($overflowdata)) {

View File

@ -67,7 +67,8 @@ $forceblockdraweropen = $OUTPUT->firstview_fakeblocks();
$secondarynavigation = false;
$overflow = '';
if ($PAGE->has_secondary_navigation()) {
$moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs');
$tablistnav = $PAGE->has_tablist_secondary_navigation();
$moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs', true, $tablistnav);
$secondarynavigation = $moremenu->export_for_template($OUTPUT);
$overflowdata = $PAGE->secondarynav->get_overflow_menu_data();
if (!is_null($overflowdata)) {

View File

@ -30,7 +30,7 @@ $blockspost = $OUTPUT->blocks('side-post');
$hassidepre = $PAGE->blocks->region_has_content('side-pre', $OUTPUT);
$hassidepost = $PAGE->blocks->region_has_content('side-post', $OUTPUT);
$PAGE->has_secondary_navigation_setter(false);
$PAGE->set_secondary_navigation(false);
$renderer = $PAGE->get_renderer('core');
$header = $PAGE->activityheader;
$headercontent = $header->export_for_template($renderer);

View File

@ -33,7 +33,7 @@ $PAGE->set_url('/user/contactsitesupport.php');
$PAGE->set_title(get_string('contactsitesupport', 'admin'));
$PAGE->set_heading(get_string('contactsitesupport', 'admin'));
$PAGE->set_pagelayout('standard');
$PAGE->has_secondary_navigation_setter(false);
$PAGE->set_secondary_navigation(false);
$user = isloggedin() && !isguestuser() ? $USER : null;
$renderer = $PAGE->get_renderer('user');