mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-57001 switchroles: Move to user menu
Take this out of the navigation and force it in the user menu.
This commit is contained in:
parent
7095f5be97
commit
70b03eff02
@ -81,9 +81,28 @@ if ($switchrole > 0 && has_capability('moodle/role:switchroles', $context)) {
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('switchroleto'));
|
||||
|
||||
require_once($CFG->dirroot.'/course/switchrole_form.php');
|
||||
$form = new switchrole_form(null, ['course' => $course]);
|
||||
$form->display();
|
||||
// Overall criteria aggregation.
|
||||
$roles = array();
|
||||
$assumedrole = -1;
|
||||
if (is_role_switched($course->id)) {
|
||||
$roles[0] = get_string('switchrolereturn');
|
||||
$assumedrole = $USER->access['rsw'][$context->path];
|
||||
}
|
||||
$availableroles = get_switchable_roles($context);
|
||||
if (is_array($availableroles)) {
|
||||
foreach ($availableroles as $key => $role) {
|
||||
if ($assumedrole == (int)$key) {
|
||||
continue;
|
||||
}
|
||||
$roles[$key] = $role;
|
||||
}
|
||||
}
|
||||
echo $OUTPUT->box(markdown_to_html(get_string('switchroleto_help')));
|
||||
|
||||
foreach ($roles as $key => $role) {
|
||||
$url = new moodle_url('/course/switchrole.php', array('id' => $id, 'switchrole' => $key, 'returnurl' => $returnurl));
|
||||
echo $OUTPUT->container($OUTPUT->single_button($url, $role), 'm-x-3 m-b-1');
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
|
@ -26,7 +26,7 @@ Feature: Rename roles within a course
|
||||
| Your word for 'Non-editing teacher' | Tutor |
|
||||
| Your word for 'Student' | Learner |
|
||||
And I press "Save and display"
|
||||
And I expand "Switch role to..." node
|
||||
And I follow "Switch role to..." in the user menu
|
||||
Then I should see "Tutor"
|
||||
And I should see "Learner"
|
||||
And I follow "Participants"
|
||||
@ -38,7 +38,7 @@ Feature: Rename roles within a course
|
||||
| Your word for 'Non-editing teacher' | |
|
||||
| Your word for 'Student' | |
|
||||
And I press "Save and display"
|
||||
And I expand "Switch role to..." node
|
||||
And I follow "Switch role to..." in the user menu
|
||||
And I should see "Teacher"
|
||||
And I should see "Student"
|
||||
And I should not see "Learner"
|
||||
|
@ -1831,6 +1831,9 @@ $string['switchdevicedefault'] = 'Switch to the standard theme';
|
||||
$string['switchdevicerecommended'] = 'Switch to the recommended theme for your device';
|
||||
$string['switchrolereturn'] = 'Return to my normal role';
|
||||
$string['switchroleto'] = 'Switch role to...';
|
||||
$string['switchroleto_help'] = 'Choose a role to get an idea of how someone with that role will see this course.
|
||||
|
||||
Please note that this view may not be perfect (<a href="https://docs.moodle.org/en/Switch_roles">See details and alternatives</a>).';
|
||||
$string['tag'] = 'Tag';
|
||||
$string['tagalready'] = 'This tag already exists';
|
||||
$string['tagmanagement'] = 'Add/delete tags ...';
|
||||
|
@ -4263,35 +4263,6 @@ class settings_navigation extends navigation_node {
|
||||
|
||||
}
|
||||
|
||||
// Switch roles
|
||||
$roles = array();
|
||||
$assumedrole = $this->in_alternative_role();
|
||||
if ($assumedrole !== false) {
|
||||
$roles[0] = get_string('switchrolereturn');
|
||||
}
|
||||
if ($adminoptions->roles) {
|
||||
$availableroles = get_switchable_roles($coursecontext);
|
||||
if (is_array($availableroles)) {
|
||||
foreach ($availableroles as $key=>$role) {
|
||||
if ($assumedrole == (int)$key) {
|
||||
continue;
|
||||
}
|
||||
$roles[$key] = $role;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_array($roles) && count($roles)>0) {
|
||||
$url = new moodle_url('/course/switchrole.php', array('id'=>$course->id, 'switchrole'=>'-1', 'returnurl'=>$this->page->url->out_as_local_url(false)));
|
||||
$switchroles = $coursenode->add(get_string('switchroleto'), $url, self::TYPE_CONTAINER, null, 'switchroleto');
|
||||
if ((count($roles)==1 && array_key_exists(0, $roles))|| $assumedrole!==false) {
|
||||
$switchroles->force_open();
|
||||
}
|
||||
foreach ($roles as $key => $name) {
|
||||
$url = new moodle_url('/course/switchrole.php', array('id'=>$course->id, 'sesskey'=>sesskey(), 'switchrole'=>$key, 'returnurl'=>$this->page->url->out_as_local_url(false)));
|
||||
$switchroles->add($name, $url, self::TYPE_SETTING, null, $key, new pix_icon('i/switchrole', ''));
|
||||
}
|
||||
}
|
||||
|
||||
// Let plugins hook into course navigation.
|
||||
$pluginsfunction = get_plugins_with_function('extend_navigation_course', 'lib.php');
|
||||
foreach ($pluginsfunction as $plugintype => $plugins) {
|
||||
|
74
user/lib.php
74
user/lib.php
@ -862,51 +862,16 @@ function user_get_user_navigation_info($user, $page, $options = array()) {
|
||||
$myprofile->pix = "i/user";
|
||||
$returnobject->navitems[] = $myprofile;
|
||||
|
||||
// Links: Role-return or logout link.
|
||||
$lastobj = null;
|
||||
$returnobject->metadata['asotherrole'] = false;
|
||||
if (is_role_switched($course->id)) {
|
||||
if ($role = $DB->get_record('role', array('id' => $user->access['rsw'][$context->path]))) {
|
||||
// Build role-return link instead of logout link.
|
||||
$rolereturn = new stdClass();
|
||||
$rolereturn->itemtype = 'link';
|
||||
$rolereturn->url = new moodle_url('/course/switchrole.php', array(
|
||||
'id' => $course->id,
|
||||
'sesskey' => sesskey(),
|
||||
'switchrole' => 0,
|
||||
'returnurl' => $page->url->out_as_local_url(false)
|
||||
));
|
||||
$rolereturn->pix = "a/logout";
|
||||
$rolereturn->title = get_string('switchrolereturn');
|
||||
$rolereturn->titleidentifier = 'switchrolereturn,moodle';
|
||||
$returnobject->navitems[] = $rolereturn;
|
||||
|
||||
$returnobject->metadata['asotherrole'] = true;
|
||||
$returnobject->metadata['rolename'] = role_get_name($role, $context);
|
||||
|
||||
}
|
||||
} 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 = "a/logout";
|
||||
$switchrole->title = get_string('switchroleto');
|
||||
$switchrole->titleidentifier = 'switchroleto,moodle';
|
||||
$returnobject->navitems[] = $switchrole;
|
||||
}
|
||||
|
||||
// Before we add the last item (usually a logout link), add any
|
||||
// Before we add the last items (usually a logout + switch role link), add any
|
||||
// custom-defined items.
|
||||
$customitems = user_convert_text_to_menu_items($CFG->customusermenuitems, $page);
|
||||
foreach ($customitems as $item) {
|
||||
$returnobject->navitems[] = $item;
|
||||
}
|
||||
|
||||
|
||||
if ($returnobject->metadata['asotheruser'] = \core\session\manager::is_loggedinas()) {
|
||||
$realuser = \core\session\manager::get_realuser();
|
||||
|
||||
@ -943,6 +908,41 @@ function user_get_user_navigation_info($user, $page, $options = array()) {
|
||||
$returnobject->navitems[] = $logout;
|
||||
}
|
||||
|
||||
if (is_role_switched($course->id)) {
|
||||
if ($role = $DB->get_record('role', array('id' => $user->access['rsw'][$context->path]))) {
|
||||
// Build role-return link instead of logout link.
|
||||
$rolereturn = new stdClass();
|
||||
$rolereturn->itemtype = 'link';
|
||||
$rolereturn->url = new moodle_url('/course/switchrole.php', array(
|
||||
'id' => $course->id,
|
||||
'sesskey' => sesskey(),
|
||||
'switchrole' => 0,
|
||||
'returnurl' => $page->url->out_as_local_url(false)
|
||||
));
|
||||
$rolereturn->pix = "a/logout";
|
||||
$rolereturn->title = get_string('switchrolereturn');
|
||||
$rolereturn->titleidentifier = 'switchrolereturn,moodle';
|
||||
$returnobject->navitems[] = $rolereturn;
|
||||
|
||||
$returnobject->metadata['asotherrole'] = true;
|
||||
$returnobject->metadata['rolename'] = role_get_name($role, $context);
|
||||
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
return $returnobject;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user