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;
}
CommentFileSizeAuthor
#4 1054046-D7-theme-switching.patch1.1 KBryanwebpage

Comments

valkum’s picture

Priority: Normal » Critical
Status: Active » Needs review

subsrcibe

naterockhold’s picture

What files should the hook_custom_theme be added to?

ryanwebpage’s picture

in 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.

ryanwebpage’s picture

StatusFileSize
new1.1 KB

ok here's the patch for 7.x-2.x-dev to switch custom themes in D7.

ajtoelle’s picture

I Couldn't get your patch to work using old school patch

patch < 1054046-D7-theme-switching.patch

Though the code worked well, when applied by hand.

mgifford’s picture

Patch 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.

mgifford’s picture

minoroffense’s picture

Status: Needs review » Closed (fixed)

Assuming the issue is resolved. Please reopen if that is not the case.