Skip to content

Commit

Permalink
MDL-68041 core_theme: New admin settings in secure page layout
Browse files Browse the repository at this point in the history
This adds two new admin settings to the theme appearance options.

Shows the lang menu in secure layout, langmenuinsecurelayout.
Shows the user's name in secure layout, logininfoinsecurelayout.

When the page layout is set to secure, these options will be in effect.
  • Loading branch information
nhoobin committed May 11, 2020
1 parent 36e5a07 commit 119a83f
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 11 deletions.
6 changes: 6 additions & 0 deletions admin/settings/appearance.php
Expand Up @@ -25,6 +25,12 @@
$temp->add(new admin_setting_configcheckbox('allowcohortthemes', new lang_string('allowcohortthemes', 'admin'), new lang_string('configallowcohortthemes', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('allowthemechangeonurl', new lang_string('allowthemechangeonurl', 'admin'), new lang_string('configallowthemechangeonurl', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('allowuserblockhiding', new lang_string('allowuserblockhiding', 'admin'), new lang_string('configallowuserblockhiding', 'admin'), 1));
$temp->add(new admin_setting_configcheckbox('langmenuinsecurelayout',
new lang_string('langmenuinsecurelayout', 'admin'),
new lang_string('langmenuinsecurelayout_desc', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('logininfoinsecurelayout',
new lang_string('logininfoinsecurelayout', 'admin'),
new lang_string('logininfoinsecurelayout_desc', 'admin'), 0));
$temp->add(new admin_setting_configtextarea('custommenuitems', new lang_string('custommenuitems', 'admin'),
new lang_string('configcustommenuitems', 'admin'), '', PARAM_RAW, '50', '10'));
$temp->add(new admin_setting_configtextarea(
Expand Down
4 changes: 4 additions & 0 deletions lang/en/admin.php
Expand Up @@ -688,6 +688,8 @@
$string['langcache_desc'] = 'Cache the language menu. If enabled, the list of available translations is cached. The cache is automatically refreshed when you install or delete a language pack via the in-built language packs management tool. If you install a new language pack manually, you have to use Purge all caches feature to refresh the cached list.';
$string['langlist'] = 'Languages on language menu';
$string['langmenu'] = 'Display language menu';
$string['langmenuinsecurelayout'] = 'Display language menu in secure layout';
$string['langmenuinsecurelayout_desc'] = 'If enabled, a user will be able to change their language when attempting a quiz or other activity using secure layout.';
$string['langpackwillbeupdated'] = 'NOTE: Moodle will try to download updates for your language packs during the upgrade.';
$string['langstringcache'] = 'Cache all language strings';
$string['languagesettings'] = 'Language settings';
Expand Down Expand Up @@ -734,6 +736,8 @@
$string['log'] = 'Logs';
$string['logguests'] = 'Log guest access';
$string['logguests_help'] = 'This setting enables logging of actions by guest account and not logged in users. High profile sites may want to disable this logging for performance reasons. It is recommended to keep this setting enabled on production sites.';
$string['logininfoinsecurelayout'] = 'Display logged-in user in secure layout';
$string['logininfoinsecurelayout_desc'] = 'If enabled, the logged-in user\'s full name will be displayed in the navigation bar when attempting a quiz or other activity using secure layout.';
$string['loginpageautofocus'] = 'Autofocus login page form';
$string['loginpageautofocus_help'] = 'Enabling this option improves usability of the login page, but automatically focusing fields may be considered an accessibility issue.';
$string['loglifetime'] = 'Keep logs for';
Expand Down
29 changes: 29 additions & 0 deletions lib/outputrenderers.php
Expand Up @@ -3462,6 +3462,35 @@ public function user_menu($user = null, $withlinks = null) {
);
}

/**
* Secure layout login info.
*
* @return string
*/
public function secure_layout_login_info() {
if (get_config('core', 'logininfoinsecurelayout')) {
return $this->login_info(false);
} else {
return '';
}
}

/**
* Returns the language menu in the secure layout.
*
* No custom menu items are passed though, such that it will render only the language selection.
*
* @return string
*/
public function secure_layout_language_menu() {
if (get_config('core', 'langmenuinsecurelayout')) {
$custommenu = new custom_menu('', current_language());
return $this->render_custom_menu($custommenu);
} else {
return '';
}
}

/**
* This renders the navbar.
* Uses bootstrap compatible html.
Expand Down
18 changes: 18 additions & 0 deletions lib/tests/behat/securelayout.feature
Expand Up @@ -18,3 +18,21 @@ Feature: Page displaying with secure layout
When I follow "Fixture link"
Then I should see "Acceptance test site" in the "nav" "css_element"
But "Acceptance test site" "link" should not exist

Scenario: Confirm that the user name is displayed in the navbar without a link
Given I log in as "admin"
And the following config values are set as admin:
| logininfoinsecurelayout | 1 |
And I am on "Course 1" course homepage
When I follow "Fixture link"
Then I should see "You are logged in as Admin User" in the "nav" "css_element"
But "Logout" "link" should not exist

Scenario: Confirm that the custom menu items do not appear when language selection is enabled
Given I log in as "admin"
And the following config values are set as admin:
| langmenuinsecurelayout | 1 |
| custommenuitems | -This is a custom item\|/customurl/ |
And I am on "Course 1" course homepage
When I follow "Fixture link"
Then I should not see "This is a custom item" in the "nav" "css_element"
27 changes: 22 additions & 5 deletions theme/boost/templates/navbar-secure.mustache
Expand Up @@ -15,7 +15,18 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
secure navbar.
@template theme_boost/navbar-secure
This template renders the top navbar.
Example context (json):
{
"output": {
"should_display_navbar_logo": "true",
"get_compact_logo_url": "http://example.com/image.png"
},
"sitename": "Moodle Site"
}
}}
<nav class="fixed-top navbar navbar-light bg-white navbar-expand moodle-has-zindex" aria-label="{{#str}}navigation{{/str}}">

Expand All @@ -26,9 +37,15 @@
{{/ output.should_display_navbar_logo }}
<span class="site-name d-none d-md-inline">{{{ sitename }}}</span>

<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
{{{ output.secure_login_info }}}
</li>
{{# output.secure_layout_language_menu }}
<ul class="navbar-nav d-none d-md-flex">
<!-- language_menu -->
{{{ . }}}
</ul>
{{/ output.secure_layout_language_menu }}
{{# output.secure_layout_login_info }}
<div class="ml-auto">
{{{ . }}}
</div>
{{/ output.secure_layout_login_info }}
</nav>
17 changes: 11 additions & 6 deletions theme/classic/templates/navbar-secure.mustache
Expand Up @@ -25,8 +25,7 @@
"should_display_navbar_logo": "true",
"get_compact_logo_url": "http://example.com/image.png"
},
"sitename": "Moodle Site",
"secure_login_info": "Logged in as test user"
"sitename": "Moodle Site"
}
}}
<nav class="fixed-top navbar navbar-bootswatch navbar-expand moodle-has-zindex">
Expand All @@ -37,9 +36,15 @@
{{/ output.should_display_navbar_logo }}
<span class="site-name d-none d-md-inline">{{{ sitename }}}</span>

<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
{{{ output.secure_login_info }}}
</li>
{{# output.secure_layout_language_menu }}
<ul class="navbar-nav d-none d-md-flex">
<!-- language_menu -->
{{{ . }}}
</ul>
{{/ output.secure_layout_language_menu }}
{{# output.secure_layout_login_info }}
<div class="ml-auto">
{{{ . }}}
</div>
{{/ output.secure_layout_login_info }}
</nav>
4 changes: 4 additions & 0 deletions theme/upgrade.txt
Expand Up @@ -4,6 +4,10 @@ information provided here is intended especially for theme designer.
=== 3.9 ===

* Add class .d-print-block to #page, #page-wrapper and #page content to fix Firefox printing problems
* A function to core_renderer has been added, secure_layout_login_info. This allows the boost and classic templates to
display the users full name in a secure layout.
* Secure layout in themes boost and classic have been modified to allow language selection as they now call the
output.secure_layout_language_menu function.

=== 3.8 ===

Expand Down

0 comments on commit 119a83f

Please sign in to comment.