While editing an openlayers preset, I get an error "Invalid argument supplied for foreach();" generated by the token list on the "behaviors" tab. The token list passed returns null. My guess is the wrong token list is generated for the zoom to location query help.
The attached patch fixes this. It renders the "geocoder" tokens instead of the "openlayers data" tokens.

Comments

ademarco’s picture

Status: Patch (to be ported) » Active

Hi basvredeling, thanks for the patch but I'm afraid that's not the solution, in this context we need to get "openlayers data" tokens. Could you paste here the full error message?

basvredeling’s picture

when adding or editing a new layer preset in the openlayers module /admin/build/openlayers/presets/add

warning: Invalid argument supplied for foreach() in ***/sites/all/modules/contrib/token/token.module on line 326.

redraven’s picture

Just confirming that I get the same error message.

ademarco’s picture

Status: Active » Postponed (maintainer needs more info)

After upgrading OpenLayers module to its latest stable version (6.x-2.0-alpha8 at the moment of writing) and with the latest OpenLayers Geocoder CVS checkout the error disappears. Could you confirm that?

steinmb’s picture

OL 6.x-2.0-alpha8 and the latest Geocoder dev. release 1 August (I could not see any CVS commits after 29 of July so I figured that this was safe to use). This it the complete error message:

PHP Fatal error: Call to undefined function token_replace() in /Users/steinmb/htdocs/sites/drupal6/sites/all/modules/openlayers_geocoder/includes/behaviors/openlayers_geocoder_zoomtolocation.inc on line 48

BUT I have not enable the token module, this option should prob. in /admin/build/openlayers/presets/* be disable/ghosted and/or Geolocator should scream dependency error when you enable the module on missing token module?

Edit: No this I do not get. Why does the function render(&$map) get called after you save the form?
function options_form($defaults = array())

steinmb’s picture

Further testing after #5 with the token module enabled.

(1)
Enable zoom to location but leaving the geocoder query field empty give me:
- No error message when saving the OL preset.
Should not the Geocoder query field be mandentory when zoom to location is enabled?
- Loading a map of on the node with the selected OL preset give this error message in the browser: Error during map rendering: TypeError: bounds.southwest is undefined

(2)
Entering an existing address in the geocoder query seem to give expected result as far as I can see.

(3)
Entering a non existing address into Geocoder query:
The WKT show the old/prev known value from test (2) but loading an map give me Error during map rendering: TypeError: bounds.southwest is undefined

Adam S’s picture

StatusFileSize
new86.2 KB

I'm getting this warning message too when I look at the Openlayers preset page. I also tested it with the basic installation. I have another development installation from one month ago and I don't have any of these problems in that site. What I mean is that it might be the upgrade from Drupal 6.17 to 6.19. I copied the working Openlayers modules and used them but in the new site I'm getting the warning.

I attached an image with the error.

basvredeling’s picture

Status: Postponed (maintainer needs more info) » Active

I tested on drupal 6.19, openlayers 2.0-alpha8, openlayers_geocoder 2.0-alpha4, token 1.14
problem persists, still the foreach error. Tokens are not properly passed to openlayers module.
So in reply to #4, no, I'm afraid I can't confirm this.

ademarco’s picture

@basvredeling: thanks for testing this out. Could you test it using the latest Openlayers Geocoder dev snapshot and see if the problem still persists?

basvredeling’s picture

tested the latest dev from 13 Aug 2010 14:16, problem remains the same.

hitfactory’s picture

Can also confirm that problem still exists on 6.x-2.x-dev as of Aug 14.

In my case the problem seems to be openlayers_views_openlayers_layers() is returning an empty $layers array. This is because I have no views using the openlayers display plugin.

ademarco’s picture

Status: Active » Postponed (maintainer needs more info)

I've checked it with the latest cvs checkout of both modules and the problem seems not to be there anymore. Could somebody check and confirm that?

mathieu’s picture

Tested today, with OpenLayers 6.x-2.0-alpha10, OpenLayers Geocoder 6.x-2.0-alpha5 and Token 6.x-1.14

I still get the message Warning: Invalid argument supplied for foreach() in (...)sites/all/modules/contrib/token/token.module on line 395

I changed the capitalization (see below) of the token source and it fixed the error.

diff --git openlayers_geocoder/includes/behaviors/openlayers_geocoder_zoomtolocation.inc
index 71f3eff..c5eabe7 100644
--- openlayers_geocoder/includes/behaviors/openlayers_geocoder_zoomtolocation.inc
+++ openlayers_geocoder/includes/behaviors/openlayers_geocoder_zoomtolocation.inc
@@ -33,7 +33,7 @@ class openlayers_geocoder_zoomtolocation extends openlayers_behavior {
       '#collapsible' => TRUE,
       '#collapsed' => TRUE,
     );
-    $form['query_tokens']['help']['#value'] = theme('token_help', 'openlayers data');
+    $form['query_tokens']['help']['#value'] = theme('token_help', 'OpenLayers Data');

     return $form;
   }
Adam S’s picture

#13 fixes the error, however, the tokens are not available.

weder’s picture

StatusFileSize
new50.85 KB

Is there any updates on this? I get the same error message, but I get an additional one from openlayers_geocoder.token.inc. This is with OpenLayers 6.x-2.0-alpha10, OpenLayers Geocoder 6.x-2.0-alpha5 and Token 6.x-1.15.

j2b’s picture

Would like to find out, if there are any movements in this issue. I'm sorry, that can not help on coding (lack of experience), but this is what I found out for now:

The modules installed:

  • openlayers-6.x-2.x-dev
  • openlayers_filters-6.x-2.x-dev
  • openlayers_geocoder-6.x-2.x-dev
  • openlayers_ui-6.x-2.x-dev
  • openlayers_views-6.x-2.x-dev
  • openlayers_plus-6.x-2.x-dev (from https://github.com/developmentseed/openlayers_plus indicated as related module on openlayers project page).

All downloaded today (13.01.2011) from Drupla.org website. Enabling all mentioned modules, there is an error message:

* warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/sites/all/modules/token/token.module on line 399.
* warning: htmlspecialchars() expects parameter 1 to be string, array given in /Applications/MAMP/htdocs/includes/bootstrap.inc on line 857.

Going through issue discussions, I stepped over this one: http://drupal.org/node/803210#comment-3069582, and modified token.module with a code in comment #7. This solution stated the following error content:

* Invalid tokens from openlayers_geocoder_token_list.
* warning: htmlspecialchars() expects parameter 1 to be string, array given in /Applications/MAMP/htdocs/includes/bootstrap.inc on line 857.

... which led me to this discussion, as I suspect errors comming from openlayers_geocoder's side. By manually disabling related modules one by one, I came upon fact, that geocoder_plus participates in this errors party. This disclosed the second warning concerning htmlspecialchars()..., but first one remained. After this I modified /openlayers_geocoder/includes/behaviours/openlayers_geocoder_zoomtolocation.inc file on line 36, by changing a Case from 'openlayers data' to 'Openlayers Data', and all errors dissapeared. (http://drupal.org/node/833086#comment-3495470)

After all and to my knowledge, here are 2 issues, and by such operations I could switch off errors, but still can not confirm (do not know how) the correctness of work of tokens. Openlayers Plus module for me seems not vital, as I wanted to check it, and it is not published on Drupal.org servers anyway. Hope this can help to move further in solutions.

muhleder’s picture

Seeing this as well, openlayers_geocoder reported as providing invalid tokens using snippet from here.

http://drupal.org/node/803210#comment-3069582

mattcasey’s picture

I was getting errors like #13 and 16 fixed it the same way, by fixing the case. Using Openlayers Geocoder 6.x-2.x-dev

muhleder’s picture

#13 just stops the tokens from being evaluated as far as I can tell.

It just means that the code in openlayers_geocoder.token.inc at openlayers_geocoder_token_list() will never get evaluated as

$type will be 'OpenLayers Data'

/**
 * Implementation of hook_token_list()
 */
function openlayers_geocoder_token_list($type = 'all') {
  $tokens = array();

  if ($type == 'openlayers data') {

    $layers = module_invoke('openlayers_views', 'openlayers_layers');
    foreach ($layers as $layer_name => $layer) {
      $list = array();
      $layer = openlayers_layer_load($layer_name);
      $features = $layer->get_features($layer->data['views']['view'], $layer->data['views']['display']);
      foreach ($features as $feature) {
        foreach ($feature['attributes'] as $attribute_name => $attribute) {
          $parts = array();
          $parts[] = $layer_name;
          $parts[] = $attribute_name;
          $key = implode('-', $parts);
          $list[$key] = t('Attriubute: <em>!attribute_name</em>', array('!attribute_name' => $attribute_name));
        }
      }
    }
    $tokens['openlayers data'] = $list;
  }

is possibly where the problem is.

davide.brognoli’s picture

I tested on drupal 6.20, openlayers 2.0-alpha10, openlayers_geocoder 2.0-alpha5, token 1.15 and I get the same error:

warning: Invalid argument supplied for foreach() in C:\webroot\camozzi\app\trunk\website\sites\all\modules\openlayers_geocoder\includes\openlayers_geocoder.token.inc on line 24.

I try to "var_dump" the $features variable and I get this result

string '<div class='openlayers-views-map'>
<div style="width: auto; height: 400px;" id="openlayers-container-openlayers-map-auto-id-0" class="openlayers-container openlayers-container-preset-default">
<div style="width: auto; height: 400px;" id="openlayers-map-auto-id-0" class="openlayers-map openlayers-preset-default"></div>
</div>
</div>' (length=352)

A var_dump of the $layer variable return me this result

object(openlayers_layer_type_openlayers_views_vector)[73]
  public 'options' => null
  public 'map' => 
    array
      empty
  public 'name' => string 'divisions_map_openlayers_1' (length=26)
  public 'title' => string '' (length=0)
  public 'description' => string 'Divisions Map - OpenLayers Data' (length=31)
  public 'data' => 
    array
      'layer_type' => string 'openlayers_views_vector' (length=23)
      'projection' => 
        array
          0 => string '4326' (length=4)
      'baselayer' => boolean false
      'type' => string 'Vector' (length=6)
      'url' => 
        array
          empty
      'options' => 
        array
          empty
      'events' => 
        array
          empty
      'views' => 
        array
          'view' => string 'divisions_map' (length=13)
          'display' => string 'openlayers_1' (length=12)
      'layer_handler' => string 'openlayers_views_vector' (length=23)
      'vector' => boolean true
  public 'export_type' => int 2

Can this information help you to resolve the problem?

barraponto’s picture

StatusFileSize
new639 bytes

I'm rerolling the first patch against dev, hope it works.

see15_aug’s picture

see15_aug’s picture

Version: 6.x-2.x-dev » 6.x-2.0-alpha5
Assigned: Unassigned » see15_aug
Category: bug » support
Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new41 KB

Hi, I am newbie and I can't understand how to use patches or where it use. I am facing same problem. I am using so please help.....

muhleder’s picture

Version: 6.x-2.0-alpha5 » 6.x-2.x-dev
Assigned: see15_aug » Unassigned
Category: support » bug

Token support is currently broken, a side effect of that is these errors are being output. You could comment out the line referred to in the patch which will stop the warnings from appearing, but it looks like no-one has had the time or knowledge to fix them properly yet.

Remove this line to stop errors.
$form['query_tokens']['help']['#value'] = theme('token_help', 'openlayers data');

Resetting issue statuses to correct values. Keeping status active as the issue seems to be confirmed.

steinmb’s picture

Priority: Normal » Major

Must be fixed before we roll #1292378: [Meta] Release alpha 6. Added to release blocker list.

steinmb’s picture

Status: Active » Needs review
StatusFileSize
new1.91 KB

OK let's try and get this rolling. First of we have this line that causes problems.
<?php $layers = module_invoke('openlayers_views', 'openlayers_layers'); ?>
We try to invoke the submodule 'openlayers_views' but it might not be turned on and views might not exist on the system.

This patch make sure we do not try to invoke non enabled modules or/and assign the NULL result from as a token.

steinmb’s picture

Status: Needs review » Fixed

No reviewers, but I went ahead and committed http://drupalcode.org/project/openlayers_geocoder.git/commit/8a7b6d6 Have been unable to find any problem with the patch.

basvredeling’s picture

Thanks, patch looks ok

Status: Fixed » Closed (fixed)

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