Skip to content

Commit

Permalink
MDL-57001 user_menu: Hide switch roles students
Browse files Browse the repository at this point in the history
Check that there are switchable roles before showing the link in the user menu.
  • Loading branch information
Damyon Wiese committed Nov 24, 2016
1 parent 22b8c5b commit 7dba450
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -929,18 +929,21 @@ function user_get_user_navigation_info($user, $page, $options = array()) {

}
} else {
// Build role-return link instead of logout link.
$switchrole = new stdClass();
$switchrole->itemtype = 'link';
$switchrole->url = new moodle_url('/course/switchrole.php', array(
'id' => $course->id,
'switchrole' => -1,
'returnurl' => $page->url->out_as_local_url(false)
));
$switchrole->pix = "i/switchrole";
$switchrole->title = get_string('switchroleto');
$switchrole->titleidentifier = 'switchroleto,moodle';
$returnobject->navitems[] = $switchrole;
// Build switch role link.
$roles = get_switchable_roles($context);
if (is_array($roles) && (count($roles) > 0)) {
$switchrole = new stdClass();
$switchrole->itemtype = 'link';
$switchrole->url = new moodle_url('/course/switchrole.php', array(
'id' => $course->id,
'switchrole' => -1,
'returnurl' => $page->url->out_as_local_url(false)
));
$switchrole->pix = "i/switchrole";
$switchrole->title = get_string('switchroleto');
$switchrole->titleidentifier = 'switchroleto,moodle';
$returnobject->navitems[] = $switchrole;
}
}

return $returnobject;
Expand Down

0 comments on commit 7dba450

Please sign in to comment.