moodle-theme_snap
moodle-theme_snap copied to clipboard
"Return to Normal Role" functionality is broken when not site admin
If you are a non-site admin in a course using the Snap theme and switch your role to student (or some other user type that doesn't have permission to view the slide-out admin menu), you cannot switch back to your original role using the "Return to normal role" button. That admin menu is hidden so there is no way to access it.
The only way to return to your original role is to log out and log back in to your moodle site.
I thought we had some code to check for this and make sure the menu displayed when you were switched from your normal role. I'll look into it and see what might be causing this not to work.
There is specific code around this area, to handle this case:
classes/renderables/settings_link.php 73: $isstudent = !$canmanageacts && !is_role_switched($COURSE->id);
I just tried this and it worked for me (logged in as a teacher, switched to a student, reverted to teacher, all on the main course page of a course) , so possibly there are specific circumstances when it doesn't work?
I've been reminded that we moved this functionality recently, as it got moved by core in 3.2, relevant code is here:
classes/output/core_renderer.php 1458: * Adds a switch role menu to a navigation node. 1464: private function add_switchroleto_navigation_node(navigation_node $item) {
Possibly if you don't have that code, but are running a more recent version of core Moode, then you won't see the option?
We do have that code in our version of snap. You can see the current version we're using here https://github.com/UniversityofPortland/moodle-theme_snap
It's up to date with moodlerooms' snap MOODLE_32_STABLE branch as of July 28th, commit 74beae63e85ce4f1ac35358cb2176d8e0e6b26c0
I think the relevant code you pasted starts on like 1454 in our classes/output/core_renderer.php
Would it be possible for you to instrument the code by adding error_log statements and check that at each step it's doing what you would expect?
e.g. this line:
$assumedrole = $this->in_alternative_role();
Is that returning true when the user is in an alternative role.
Presumably one of the assumptions that the code is making is wrong for your setup, but it seems to be working for me so it would be good to find out what is different.
Hi, I have the same issue in my installation. I tried to print error_logs, but I couldn't find the cause.
What is happening: After you switch to another role, the inner HTML of 'side-pre' is empty: https://github.com/moodlerooms/moodle-theme_snap/blob/9400422e65d151f44abee943adc83892c4c2d40f/classes/output/core_renderer.php#L377
$output = '<div id="moodle-blocks" class="clearfix">';
$output .= $editblocks;
$output .= $OUTPUT->blocks('side-pre'); // INNER HTML EMPTY
$output .= '</div>';
And the HTML printed is:
<div id="moodle-blocks" class="clearfix">
<aside id="block-region-side-pre" class="block-region" data-blockregion="side-pre" data-droptarget="1"></aside>
</div>
An Administrator sees:
<div id="moodle-blocks" class="clearfix">
<div class="text-center">
<a href="http://somesite/moodle32/course/view.php?id=10&sesskey=something&edit=on" class="btn btn-primary">Edit blocks</a>
</div>
<br>
<aside id="block-region-side-pre" class="block-region" data-blockregion="side-pre" data-droptarget="1">
<a href="#sb-2" class="sr-only sr-only-focusable">Skip Administration</a>\n\n<aside id="inst17"\n ...
My current assumption is that, when you switch roles, something go wrong and the inner HTML of 'side-pre' can't be generated.
About the previous suggestion, I check $assumedrole and the value is right. The interesting thing here is that, when set_admin_menu_instance() is called (classes/renderables/settings_link.php), it finds the right instanceid (value=17) that should be use to print <aside id="inst17">. It looks like "inst17" can't be printed. If we know how that piece of HTML is created, we might be able to find the bug.
Just to inform that I tested with Moodle 3.3 (and the latest Snap release in Github for that version) and the problem persists.