Skip to content

Commit

Permalink
MDL-72481 admin: Render the site admin navigation menu as tablist
Browse files Browse the repository at this point in the history
only render the secondary nav as tablist if it is for the site admin tabs

Co-authored-by: Shamim Rezaie <shamim@moodle.com>
  • Loading branch information
junpataleta and rezaies committed Mar 15, 2022
1 parent 1f21daf commit 6937d87
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 16 deletions.
3 changes: 2 additions & 1 deletion admin/search.php
Expand Up @@ -11,6 +11,7 @@

$context = context_system::instance();
$PAGE->set_context($context);
$PAGE->set_secondary_navigation(true, true);

$hassiteconfig = has_capability('moodle/site:config', $context);

Expand Down Expand Up @@ -91,7 +92,7 @@
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',
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/componentlibrary/docspage.php
Expand Up @@ -76,7 +76,7 @@
$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');
Expand Down
2 changes: 1 addition & 1 deletion error/index.php
Expand Up @@ -36,7 +36,7 @@
$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
Expand Down
4 changes: 2 additions & 2 deletions index.php
Expand Up @@ -103,10 +103,10 @@
$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');
Expand Down
25 changes: 21 additions & 4 deletions lib/pagelib.php
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -2213,21 +2218,33 @@ public function include_region_main_settings_in_header_actions() : bool {
/**
* 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;
}

/**
* Check if the secondary navigation should be rendered.
*
* @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.
*
Expand Down
2 changes: 1 addition & 1 deletion my/courses.php
Expand Up @@ -51,7 +51,7 @@
$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');
Expand Down
2 changes: 1 addition & 1 deletion my/index.php
Expand Up @@ -88,7 +88,7 @@
$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) {
Expand Down
2 changes: 1 addition & 1 deletion my/indexsys.php
Expand Up @@ -51,7 +51,7 @@
$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.
Expand Down
3 changes: 2 additions & 1 deletion theme/boost/layout/columns2.php
Expand Up @@ -38,7 +38,8 @@
$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)) {
Expand Down
3 changes: 2 additions & 1 deletion theme/boost/layout/drawers.php
Expand Up @@ -67,7 +67,8 @@
$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)) {
Expand Down
2 changes: 1 addition & 1 deletion theme/classic/layout/columns.php
Expand Up @@ -30,7 +30,7 @@

$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);
Expand Down
2 changes: 1 addition & 1 deletion user/contactsitesupport.php
Expand Up @@ -33,7 +33,7 @@
$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');
Expand Down

0 comments on commit 6937d87

Please sign in to comment.