Custom themes are handled a little differently in Drupal 7. The current method used in Mobile Tools is not working in Drupal 7.
You now need to hook_custom_theme instead of setting the global var $custom_theme. It can be handled like so. Sorry I'd write a patch but I have not had much luck with CSV lately. Can't wait until Drupal is ported to git.
/**
* Implements hook_custom_theme().
*/
function mobile_tools_custom_theme() {
global $mobile_tools_device;
return mobile_tools_switch_theme($mobile_tools_device);
}
and instead of having mobile_tools_switch_theme return true or false have it return the custom them name or false.
/**
* Being called in the hook_boot() implementation
* This function is in charge of changing to the mobile theme
*/
function mobile_tools_switch_theme($device) {
global $custom_theme, $conf;
// check if theme switching is forced
$current_url_type = mobile_tools_is_mobile_site();
if (($current_url_type == 'mobile' && variable_get('mobile-tools-theme-switch', '' ) == 'mobile-tools-mobile-url') || (variable_get('mobile-tools-theme-switch', '' ) == 'mobile-tools-mobile-device' && $device['type'] == 'mobile') ) {
$group = $device['group'];
$mobile_detection_module = variable_get('mobile-tools-device-detection', 'mobile_tools');
if (variable_get($mobile_detection_module . '_' . $group . '_enable', '') == 1) {
$custom_theme = variable_get($mobile_detection_module . '_' . $group . '_theme', $conf['theme_default']);
return $custom_theme;
}
else {
$custom_theme = variable_get('mobile_tools_theme_name', $conf['theme_default']);
return $custom_theme;
}
}
return FALSE;
}
Comments
Comment #1
valkum commentedsubsrcibe
Comment #2
naterockhold commentedWhat files should the hook_custom_theme be added to?
Comment #3
ryanwebpage commentedin the module file mobile_tools.module. Now that drupal has been ported to git I'll put a patch up when I get a chance. I see that there has been an update to mobile tools since I posted this and it does not include the theme switching fix. I will try to create the patch today.
Comment #4
ryanwebpage commentedok here's the patch for 7.x-2.x-dev to switch custom themes in D7.
Comment #5
ajtoelle commentedI Couldn't get your patch to work using old school patch
patch < 1054046-D7-theme-switching.patchThough the code worked well, when applied by hand.
Comment #6
mgiffordPatch worked for me, but applying git patches is a bit different.
I needed to specify I wanted it applied to mobile_tools.module
I'm still not able to get it to switch themes however when browsing with a mobile device.
Comment #7
mgiffordAlso, worth checking out:
http://stackoverflow.com/questions/5151711/switching-themes-in-drupal-7-...
Comment #8
minoroffense commentedAssuming the issue is resolved. Please reopen if that is not the case.