Commit e250631d authored by Richard Mansfield's avatar Richard Mansfield

Add config option to allow users to change their theme

Part of bug #793308

Adds a config.php option which lets users change their theme (for
browsing) via a drop-down on the Settings page.  The allowed themes
are the same set accessible to the user when the viewthemes option is
availiable.  Any theme which is restricted to one or more institutions
in its themeconfig.php file is not available in the drop-down unless
the user is a member of one of those institutions.

Change-Id: If6a7db9a4c160e16b38d22a074c128777968c4ca
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent c1fda6fe
......@@ -174,8 +174,9 @@ function accountprefs_submit(Pieform $form, $values) {
update_send_count($u,true);
}
// Remember the user's language pref, so we can reload the page if they change it
// Remember the user's language & theme prefs, so we can reload the page if they change them
$oldlang = $USER->get_account_preference('lang');
$oldtheme = $USER->get_account_preference('theme');
// Set user account preferences
foreach ($expectedprefs as $eprefkey => $epref) {
......@@ -194,13 +195,23 @@ function accountprefs_submit(Pieform $form, $values) {
db_commit();
if (isset($values['lang']) && $values['lang'] != $oldlang) {
$updatelang = isset($values['lang']) && $values['lang'] != $oldlang;
$updatetheme = isset($values['theme']) && $values['theme'] != $oldtheme;
if ($updatetheme) {
$USER->update_theme();
$message = get_string('prefssaved', 'account');
}
if ($updatelang) {
// The session language pref is used when the user has no user pref,
// and when logged out.
$SESSION->set('lang', $values['lang']);
$message = get_string_from_language($values['lang'], 'prefssaved', 'account');
}
if ($updatelang || $updatetheme) {
// Use PIEFORM_CANCEL here to force a page reload and show the new language.
$returndata['location'] = get_config('wwwroot') . 'account/index.php';
$SESSION->add_ok_msg(get_string_from_language($values['lang'], 'prefssaved', 'account'));
$SESSION->add_ok_msg($message);
$form->json_reply(PIEFORM_CANCEL, $returndata);
}
......
......@@ -271,3 +271,7 @@ $cfg->favicondisplay = 'http://www.google.com/s2/favicons?domain=%s';
// site is not in production mode, and that some data may be missing and/or
// out of date
$cfg->productionmode = true;
// If true, users can change their preferred theme for browsing the site. The user's theme preference
// will override any site, institution, or page theme.
// $cfg->themeprefs = true;
......@@ -261,6 +261,23 @@ function general_account_prefs_form_elements($prefs) {
'help' => true,
'ignore' => count($languages) < 2,
);
if (get_config('themeprefs') && !in_admin_section()) {
// get_user_accessible_themes() returns 'sitedefault' to mean fall back to the site or
// institution theme. This won't work for account prefs, where 'sitedefault' is just
// a theme that doesn't exist. So change the 'sitedefault' key to '', and the empty
// preference will be interpreted as "No theme selected".
$themes = array_reverse(get_user_accessible_themes());
$themes[''] = $themes['sitedefault'];
unset($themes['sitedefault']);
$themes = array_reverse($themes);
$elements['theme'] = array(
'type' => 'select',
'defaultvalue' => $prefs->theme,
'title' => get_string('theme'),
'options' => $themes,
'ignore' => count($themes) < 2,
);
}
$elements['addremovecolumns'] = array(
'type' => 'checkbox',
'defaultvalue' => $prefs->addremovecolumns,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment