I have just downloaded mobile tools dev version and all of the required modules along with. I went to context to create a context and the I get the following error on all my pages:

Warning: Invalid argument supplied for foreach() in mobile_tools_context_init() (line 23 of /home/clients/websites/w_saros/public_html/saros/sites/all/modules/contrib/mobile_tools/mobile_tools_context/mobile_tools_context.module).

Is there a patch or something that I am missing?

Comments

jlea9378’s picture

I'm getting the same error. I'm using the Dec-14-2011 7.x-2.x-dev version of Mobile Tools and the Dec-23-2011 7.x-3.x-dev version of Context.

leewoodman’s picture

subscribe

mellenger’s picture

any update on this. I'm just getting my mobile modules set up and this came up.

mikefyfer’s picture

Same here:
Mobile Tools 7.x-2.x-dev
Context 7.x-3.0-beta2
Persistent URL 7.x-1.0-beta1
Chaos tools 7.x-1.0-rc1
Spaces 7.x-3.x-dev
Features 7.x-1.0-beta6
ThemeKey 7.x-2.0

but now that i see there isn't a stable release of any of those, it doesn't really surprise me...

play4quarters’s picture

I'm having the same issue.

Any update available please?

thanks!

jsfwd’s picture

The problem is that on line 23:
$devices = mobile_tools_get_active_device_group() <-- returns the active device groups as an array, FALSE otherwise.

So if you have no active device groups and a boolean is returned then it will break the foreach().

Around line 23, there needs to be a type check to make sure $devices is an array...

// Returns active devices array, false otherwise
if (gettype($device) == 'array') {
  // Init all active device groups
  foreach($device as $key => $group) {
    $plugin->execute($group['type']);            
  }
}
dddbbb’s picture

Same error right here.

7.x-2.x-dev, 2011-Dec-14

merilainen’s picture

The fix mentioned in #6 gets rid of the error message, but when I use devel's dsm function to see what the $device contains (dsm($device);), I don't get anything else than an empty array with three empty cells.

jlea9378’s picture

Any chance the fix in #6 (which solves the problem on my installation) can get committed to Dev?

areikiera’s picture

Also an issue on the 7.x-3.x-dev version. Could someone provide guidance on how to correct for that version, and the file that the fix should be applied to?

Thanks!

jlea9378’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev

I'm also getting this in the mobile_tools 7.x-3.x-dev (2012-Apr-25) release.

Warning: Invalid argument supplied for foreach() in mobile_tools_context_init() (line 20 of /var/www/html/drupal_test/sites/all/modules/mobile_tools/mobile_tools_context/mobile_tools_context.module).

jlea9378’s picture

Title: Mobile Tools Context: Invalid argument on line 23 » Warning: Invalid argument supplied for foreach() in mobile_tools_context_init()

The fix in comment #6 worked for me.

yashadev’s picture

Assigned: Unassigned » yashadev
Status: Active » Needs review
StatusFileSize
new998 bytes

Here's a patch that will fix the bool-array bug specified above

Jeff Burnz’s picture

Patch applies with one white space error, fixes the issue. I don't know enough about this to RTBC but the error message does go away.

$plugin->execute($group['type']);

yashadev’s picture

Should be no white space trailing

awolfey’s picture

I wonder if it might be better to fix mobile_tools_get_active_device_group() so that it returns an empty array instead of false. However, it looks like other functions are expecting a string to be returned. See mobile_tools_html_head_alter(&$head_elements) for one example.

So maybe there's more work to be done here.

yashadev’s picture

Very good point. The variable returned, $device_groups, is set to an array containing and id and a type of the mobile device; the functions that are calling mobile_tools_get_active_device_group() are expecting to get an array back. So yeah, I think it's better to return an empty array if it's not set rather than returning FALSE. I also checked the functions that are calling mobile_tools_get_active_device_group(), and they either check if the variable returned is empty or equal to a certain value.
Example:

  $active_groups =  mobile_tools_get_active_device_group();
  // Since we can only redirect to one site, we take the first returned device
  // group
  if (!empty($active_groups)) {
    $device_group = $active_groups[0];    
  }

and

function mobile_tools_html_head_alter(&$head_elements){
  $site = mobile_tools_get_active_device_group();
  if(variable_get('mobile_tools_add_header', 1) && $site == 'mobile'){
    // Add the viewport settings
    $head_elements['viewport'] = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'name' => 'viewport',
        'content' => 'user-scalable=no, width=device-width, maximum-scale=1.0',
      ),
    );

So the following patch fixes the mobile_tools_get_active_device_group() function to return an empty array in case it isn't set instead of returning a FALSE value.

Please test it and let me know if the error still exists.

devin carlson’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.56 KB

An updated patch that includes the fix in #17 along with some additional documentation changes.

devin carlson’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x-3.x.

As awolfey said in #16, mobile_tools_html_head_alter() checks to see if the value returned from mobile_tools_get_active_device_group is a string but the way the function works now, that will never work. This patch does nothing to break or fix that functionality, so I'm committing it.

A separate issue should be opened up to fix mobile_tools_html_head_alter().

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.