Hi,

Ive updated to the latest version, and it doesn't seem to be working.

Browsecap returns the browser details correctly, but where exactly in the code, does it tell Drupal to change its theme?

Im using D7.15.

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quiptime’s picture

Status: Active » Postponed (maintainer needs more info)

Ive updated to the latest version, and it doesn't seem to be working.

What is the indicator that MSw does not work?

webadpro’s picture

Its not changing theme when viewing in either an iPhone nor a blackberry phone.

In the boot everything gets set. Although the theme is never changed even when $conf['theme_default'] is properly set. Now im wondering if its a server configuration issue. Or the function hook_custom_theme() should be used rather than the $conf file, since $conf variables can get overwritten by other modules.

webadpro’s picture

Actually, i have cloned your hook_boot function and inserted as:

function mobile_switch_custom_theme() {
   global $conf;

  // Initialize the new variables here (as fallback) if configured the
  // 'Mobile theme' setting  with the option 'Do not use'.
  $conf['mobile_switch_ismobiledevice'] = FALSE;
  $conf['mobile_switch_ismobiletheme'] = FALSE;
  $conf['theme_mobile'] = FALSE;
  // Preserve the configuration variables.
  $conf['mobile_switch_theme_default'] = variable_get('theme_default', 'bartik');
  $conf['mobile_switch_theme_mobile'] = variable_get('mobile_switch_mobile_theme', 'none');
  // Use the mobile theme on admin pages.
  $get['admin'] = variable_get('mobile_switch_admin_usage', FALSE);

  if (defined('MAINTENANCE_MODE') || (stristr($_GET['q'], 'admin') && $get['admin'] == FALSE) || $conf['mobile_switch_theme_mobile'] == 'none' ) {
    return;
  }

  $get['deskbrowser'] = variable_get('mobile_switch_deskbrowser', FALSE);
  $get['developer'] = variable_get('mobile_switch_developer', FALSE);
  $get['theme_default'] = $conf['mobile_switch_theme_default'];
  $get['browser'] = mobile_switch_browscap_get_browser($get['developer']);

  if (variable_get('mobile_switch_prevent_devices', FALSE) == TRUE) {
    if ($get['browser']['prevent_device'] == TRUE) {
      return;
    }
  }

  $get['theme_cookie'] = FALSE;

  if ($get['browser']['ismobiledevice'] == 1 || ($get['browser']['ismobiledevice'] == 0 && $get['developer'] == 1 && $get['deskbrowser'] == 1) || $get['deskbrowser'] == 1) {
    return $conf['mobile_switch_theme_mobile'];
	}
}

That seems to fix my issue. Also, i think using "hook_custom_theme" is a better solution.

slowflyer’s picture

Version: 7.x-1.4 » 6.x-1.0-beta1

Same on the D6 version, theme is not switched.

webadpro’s picture

Version: 6.x-1.0-beta1 » 7.x-1.4

Please don't change the Version though.

thanks

curiosity26’s picture

Component: Miscellaneous » Code
Status: Postponed (maintainer needs more info) » Patch (to be ported)
FileSize
2.79 KB

Here is a patch that fixed the issue for us. This fixes the theme switching as well as an issue with the 'Preventing' switch being ignored. We've tested on desktop using Firefox, Chrome, IE 7/8/9, iPad, iPhone, Galaxy Tab, various Android user agents. Try it out. I hope this fixes the issue.

webadpro’s picture

I feel like hook_custom_theme should be used rather than boot, but that's maybe just me.

deelite’s picture

Thanks for your work!

But how can a apply this patch?

deelite’s picture

OK, found that:

www.tylerfrankenstein.com/user/4/code/apply-patch-drupal-module

Had to install the package patch before.

curiosity26’s picture

No problem! My company started using Mobile Switch for Drupal 6 and found it to be the best option for mobile switching, so patching these few bugs was our contribution to you work. Thanks :)

Drupal has some good information on patches and applying patches as well: http://drupal.org/patch/apply

Git makes it much easier to create and apply patches directly to the Drupal repository.

quiptime’s picture

@curiosity26,

thanks for your patch.

This is an issue reported to a branch 7.x-1+. Patches for 6.x-1+ - please create a new issue to a corresponding release.

@webadpro,

I will not abandon the use of hook_boot().

Please test MSw 7.x-1.5.

webadpro’s picture

Even though its V1, using boot isn't the proper way. Since other module such as themekey will make it impossible to make this work since it uses the hook_custom_theme which breaks this module.

I mean hook_custom_theme is the hook to use to alter a theme.

This hook can be used to dynamically set the theme for the current page request. It should be used by modules which need to override the theme based on dynamic conditions (for example, a module which allows the theme to be set based on the current user's role).

Please note I'm having the same issue with V2.

tsedlmeier’s picture

#3 work for me for 7.x-1.5

I think the same error is in the v2, ismobiledevice is true, but there's no switching to the mobile theme.

webadpro’s picture

Must be because of other module such as themekey conflits with this module.

webadpro’s picture

Status: Patch (to be ported) » Needs review
bradjones1’s picture

Version: 7.x-1.4 » 7.x-2.x-dev
Priority: Normal » Major
FileSize
1.58 KB

Some cleanup and love on this issue:

  • Title updated to better reflect current work/above discussion
  • This appears to be major - see below re: not working OOTB
  • Version updated to 7.x-2.x-dev as this appears to affect this latest version as much if not more. Plus in keeping with Drupal best practice, we can fix in 2.x and backport.
  • The attached patch is in the spirit of #3 above (which isn't diff-ed) but also cleans up the function documentation and moves the drupal_alter implementation to maintain compatibility with other modules like mobile_switch_block.

As some others have observed, this just wasn't working for me OOTB with a hook_boot() implementation, and that seems to be a less-desirable way of altering theme preference, especially if other modules wish to have a say. This module's API (limited as it is) still calls it a "boot" hook but that's easily cleaned up later if the module maintainer likes this change.

For what it's worth, I've also found the following patches are needed for proper functioning and likely block a "stable" release of 2.x:

bradjones1’s picture

Title: Lastest version doesn't seem to be working » Implement hook_cutom_theme() instead of hook_boot()
ykyuen’s picture

Hi all,

Thanks for all the suggested solutions and patches.

I have applied all 3 patched as suggested by bradjones1 in #16. but the problem is not completely resolved as i found that sometimes i need to refresh a few times of the "front" page to work. but for other pages. most of the time it could switch to mobile theme.

anyone has similar problem? the website is running on nginx with microcache enabled, not sure if that is related to the problem.

Thanks again.

Kit

bradjones1’s picture

Kit - By needing to refresh the front page, do you mean you get some sort of error on occasion getting it to load, or bring up a cached copy, or...?

ykyuen’s picture

thanks for the quick reply.

there is no error and i guess it is a cached page. so i wonder there maybe sth related to the nginx microcache.

i am trying to ask the hosting team to disable the microcache and see if the problem persists. will update this issue if i have any findings.

das-peter’s picture

I'm not sure if it's the best idea to use hook_custom_theme() only - maybe we could keep the detection in hook_boot() to ensure the variables are set as early as possible and later use the variables in hook_custom_theme().
But that's just an idea.

I've removed some trailing white-spaces in the patch and couldn't resist to do some other clean-up.
E.g. I didn't see to point to cast a variable ((bool)) and then do a typed check (===) on it - using an untyped check without casting will give the same result.
Further I didn't get the idea of having two if statements for something that can be easily checked in a single if with two conditions.

brianbrarian’s picture

The patch in #21 works for me to resolve a conflict with Themekey, but only after I gave Mobile Switch a higher weight than Themekey in the system table.

das-peter’s picture

I've found an issue in Drupal core that could / will affect this. I've a draft of an issue report only yet: http://dropbucket.org/node/806
I'll create a proper issue and a patch soon.

Update: Proper issue report created #2086335: Bootstrap issue with theme initialization causes hook_custom_theme() never to be invoked