Download & Extend

Mobile tools + Display Suite: buildmode-mobile regardless of User-Agent => fix for mobile_tools_site_type

Project:Mobile Tools
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

I'm trying to build my first mobile site, so I'm learning a bit and I might have done something wrong. But I do think I ran into a bug. I'm a big fan of Display Suite so I was happy to see that Mobile Tools has support for Display Suite, but with Mobile Tools enabled (and the Display Suite support) I somehow get for all nodes, for all User-Agents.

I'll try to find out why it's doing that but some help about where to look would be highly appreciated.

Comments

#1

I thought it might have something to do with cache so I turned that off, but it's still acting weird.

This seems a relevant piece of code:

function mobile_tools_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'load' && mobile_tools_site_type() == 'mobile' && variable_get('mobile_tools_enable_build_mode', 0)) {
$node->build_mode = 'mobile';
}
}

So I suspected a problem with mobile_tools_site_type().
I added a static caching around it and now things work as expected!

<?php
function mobile_tools_site_type() {
  static
$site_type = NULL;

  if (
$site_type != NULL) {
   
$site_detection = variable_get('mobile-tools-site-type-detection', 'mobile_tools');
   
drupal_load('module', $site_detection);
    if (
$site_detection == 'mobile_tools') {
     
$site_type = _mobile_tools_site_detection();;
    }
    else {
     
$site_type = module_invoke($site_detection, 'is_mobile_site');
    }
  }
  return
$site_type;
}
?>
AttachmentSize
mobile_tools_static_ds_fix.patch 752 bytes

#2

Title:Mobile tools + Display Suite: buildmode-mobile regardless of User-Agent» Mobile tools + Display Suite: buildmode-mobile regardless of User-Agent => fix for mobile_tools_site_type
Status:active» needs review

#3

Oops. This was working better but it was wrong. I noticed the problem when I actually wanted to start using the buildmode-mobile.
The condition should be:

if ($site_type != NULL) {

nobody click here