Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This worked fine with anon users.
After much frustration, it seems something happens when user_save() is called so that changing $user->theme doesn't immediately change the displayed theme. I moved $user->theme = $form_values['theme']; out of the if statement and put it BEFORE user_save() and it worked.
I'm still a little confused as to why, but this change fixed our problem... I'll let another investigate further.
I changed the following code
function switchtheme_switch_form_submit($form_id, $form_values) {
global $user;
if ($user->uid > 0) {
// Save the setting in the db for logged in users.
// We do not validate the input here, because that is done in init_theme()
// already.
if (user_save($user, array('theme' => $form_values['theme']))) {
$user->theme = $form_values['theme'];
}
$_SESSION['custom_theme'] = $form_values['theme'];
}
elseif (user_access('switch theme')) {
// Save the setting in the session for anonymous users.
$_SESSION['custom_theme'] = $form_values['theme'];
}
}
TO:
function switchtheme_switch_form_submit($form_id, $form_values) {
global $user;
if ($user->uid > 0) {
// Save the setting in the db for logged in users.
// We do not validate the input here, because that is done in init_theme()
// already.
$user->theme = $form_values['theme'];
user_save($user, array('theme' => $form_values['theme']));
$_SESSION['custom_theme'] = $form_values['theme'];
}
elseif (user_access('switch theme')) {
// Save the setting in the session for anonymous users.
$_SESSION['custom_theme'] = $form_values['theme'];
}
}
Comment | File | Size | Author |
---|---|---|---|
#12 | switchtheme-DRUPAL-6--1.user_.patch | 4.75 KB | sun |
#12 | switchtheme-DRUPAL-5.user_.patch | 3.96 KB | sun |
#9 | switchtheme-DRUPAL-6--1.user_.patch | 967 bytes | sun |
#6 | switchtheme.module.patch | 681 bytes | Agileware |
Comments
Comment #1
sunCould you please compile a list of other contrib modules you have enabled?
Comment #2
frankcarey CreditAttribution: frankcarey commentedwe have a lot :) is there an easy way to do that? module perhaps?
-Thanks
Comment #3
christefano CreditAttribution: christefano commented@TextPlease: try Enabled modules.
Comment #4
sunmeh... installing a module for this purpose is quite a big overhead - just execute this query:
Comment #5
Agileware CreditAttribution: Agileware commentedSame problem, updated code works for me.
Comment #6
Agileware CreditAttribution: Agileware commentedHere's a patch with the code to make life easier.
Comment #7
Agileware CreditAttribution: Agileware commentedComment #8
Agileware CreditAttribution: Agileware commentedComment #9
sunWell. Basically, attached patch should be the cleanest fix. However, untested - and please do not test this one on production sites.
Comment #10
Agileware CreditAttribution: Agileware commentedI've checked the Drupal 6 patch and it's the same as the Drupal 5 patch. We've got the Drupal 5 patch working on a production website and I can confirm it works.
Comment #11
sunWhat means you "checked the Drupal 6 patch"? Actually it's not the same. That's why I was asking for testing (again, due to changes in the patch on test sites only, please).
Comment #12
sunTested this myself; fixed some more glitches, and committed attached patch(es) to all branches.