I'm trying to render marker types in my gmap style, basing on php code on customfield.
So, I go to gmap "Style options", select
Marker handling: Use marker field,
Marker field: PHP code (my customfield with my php code)

and in my php code, for testing I just do echo 'Cluster'; and I expect marker type to switch to 'Cluster'

And that doesn't work.

It looks like gmap defines marker type earlier then PHP code field is attached to views rows.
If I go to /modules/gmap/gmap_plugin_style_gmap.inc and find a line where gmap defines marker type:
(line 119)

else if ($this->options['markers'] == 'field') {            
            if (!empty($row->{$marker_field})) {
              $markername = $row->{$marker_field};
            }           
          }

you can see that gmap tries to define marker type using $row object. If I do var_dump($row) here, I see no my customfield, but I see all other fields, that were retrieved from database. It looks like phpcode customfield is attached later, as it's not using db source. Can you please comment on this? What should I do to make my approach work?
Thanks in advance.
gmap 6.x-1.1-rc1
views_customfield 6.x-1.0

Comments

restyler’s picture

Any clue?

agileadam’s picture

Having the exact same problem here. I'll post again if I come up with a workaround.

Anonymous’s picture

A related problem I'm experiencing right now is that I can only have the "Use marker field" option for my custom marker set if I specify the marker name in small caps in the cck text field of my content. Try 'cluster' in other words?

dageshi’s picture

Seemingly customfield is never setting the row variable. You can do it manually like so


$data->customfield_phpcode_3 = "small red";

Your field name might be different.

I will have a poke around and see if I can find out where customfield is going wrong.

rudiedirkx’s picture

Using gmap 1.1 I'm 'debugging' Gmap's class gmap_plugin_style_gmap.

It appears Views renders fields after Gmap sets up the markers. (We already knew that.) Which means the list of View fields you can choose from in the view settings (under Marker field under Marker handling) is bogus. Only the 'native' fields are usable, not the created fields.

So PHP code fields aren't usable and all 'rewrite this field as'-fields aren't usable and globals aren't usable etc etc.

Which is a BIG BIG bumber! And the only solution is to postpone render() until after the view renders its fields. Or render the fields in render()... but that's not very performance friendly.

Max_Headroom’s picture

I needed to change the marker type based on a CCK select list.
This is my code in Views custom field:


switch ($data->[NAME OF YOUR SELECT FIELD]) {
  case 0:
    $output = 'small green';
    break;
  
  case 1:
    $output = 'small dgreen';
    break;
  
  case 2:
    $output = 'small lblue';
    break;
}
return $output;

In the Gmap style settings, select the Customcode: PHP code as the Marker field.
Hope it helps.

FooZee’s picture

@Max_Headroom,

What is the version of your GMAP and views custom fields ? what you are saying seems pretty much logical, but I don't know why it is not working on my site :( could you post more details or maybe demo would be amazing :)

Thanks

Holoduke’s picture

After reading your posts, I tried a different approach.

I created a custom views template for desired field. At field template i could use PHP.

I like to use CustomFields module to solve this problems, but don't forget: Drupal usually have different ways to get the same result.

kansaj’s picture

by some chances I was stumbling on the problem that sometimes views php field do not return the expected value to the Gmap plugin, where the the code in the output does the job...

deweydb’s picture

Issue summary: View changes

If anyone runs into this problem. I solved it by switching from the views php field module to the views custom field module.

jomarocas’s picture

hi @deweybd how this working in drupal 7, i cannot make this with views php