How to display map for in a block on sidebar?
zigma - July 23, 2007 - 03:12
| Project: | GMap Addons |
| Version: | 5.x-1.x-dev |
| Component: | Miscellaneous |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I am trying to display the map in a block on sidebar. Here is function that i have been playing with to do this job.
gmap_cck_field_formatter($field, $item, $formatter, $node)
$item: I pass that value stored for gmap_cck type field on the node
$formatter: I don't pass anything. it seems to take 'default'
$node: I pass $node
$field: This seems to have complete definition of that gmap_cck type field. And i don't know how to get this field definition. WHAT DO I NEED TO PASS FOR THIS PARAMETER?
Is there a better way to display the map in a block for the node?

#1
I haven't displayed a block in a sidebar, but I remember having seen a module "node as block" or something like that, maybe that could help.
That said, you shouldn't call gmap_cck_field_formatter() directly, but rather content_format() instead.
In order to work you can pass the fieldname of the gmap_cck field (i.e. 'field_myfield') as first parameter to content_format().
If you succeed please post here how you did it.
#2
Thank you ray,
I tried that. It seems the function is not able to get widget related info. It just throws text instead of rendering the map.
#3
Seems like content_format does make right call. However gmap_cck_field_formatter
is not doing the job.
#4
Now i find something weird.
when i directly call function gmap_cck_field_formatter passing field name (which is field_my_loc_map) for $field. It displays the map.
print gmap_cck_field_formatter('field_my_loc_map', $node->field_my_loc_map[0], '', $node);But the above call throws two warnings-
####################
warning: Invalid argument supplied for foreach() in d:\apache group\Apache\~ ~ ~\modules\gmap_addons\gmap_cck.module on line 518.
warning: array_merge() [function.array-merge]: Argument #2 is not an array in d:\apache group\Apache\~ ~ ~\modules\gmap_addons\gmap_cck.module on line 279
####################
Here is what i find at those 2 lines--
Line #518: foreach ($nrf as $delta => $item) {
Line #279: $map = array_merge(gmap_defaults(), $field, $m);
When i build array for field and call gmap_cck_field_formatter like-
$field = content_fields('field_my_loc_map');print gmap_cck_field_formatter($field, $node->field_my_loc_map[0], '', $node);
It does not display that warning. But it does not display the map as well.
Calling content_format() does exactly that. It passes an array for $field. Therefore it does not throw any warning but it does not display map as well.
#5
1. don't use gmap_cck_field_formatter() directly, use content_format() instead
2. don't pass an empty string as 3rd parameter (formatter), use 'default' instead
for the warning insert the following code in line 516 (after $fname = ...):
if (!isset($node->$fname) || !count($node->$fname)) return;I'll do a new release a bit later.
#6
ray,
thank you for quick help.
When i use content_format(), i don't get any warning with or without that statement to be inserted at #516.
print content_format('field_test_location_map', $node->field_my_loc_map[0], 'default', $node);However it does not display any map. I can see that field on page source though. So it seems all the formatting are not done properly.
When i use the following call.
print content_format('field_test_location_map', $node->field_my_loc_map[0], 'default', $node);a) it displays the map
b) with that statement at line#516, one of the warning is gone. However one of them referring to line#279 is still there
#7
If the warning in line 279 is still there, then your first parameter to content_format() seems to be wrong. Looking at your example, I'd expect the line to look like this:
echo content_format('field_my_loc_map', $node->field_my_loc_map[0], 'default', $node);And a small correction of my last statement: the value of the formatter argument (parameter 3) currently doesn't matter. But it's still a good idea to not pass it empty ;-)
#8
>>>then your first parameter to content_format() seems to be wrong
I tried creating a new field to test it. that's why you found different field name in my last message.
I still observe the same behavior-
1) with content_format()
a) no warning
b) map does not show up even though i can see it takes some blank space on screen
2) with gmap_cck_field_formatter()
a) throws warning at line#279
b) map shows up
#9
If you use gmap_cck_field_formatter() directly, you cannot use the fieldname as first paramter.
What's the result of
$field = content_fields('field_my_loc_map');?Because if you don't get a valid field configuration array here, the whole thing cannot work.
That would also explain the call to content_format() not working - the content module cannot find the field definition you're asking it for.
#10
ok. here is what i find in html source. this seems to be related to calls to theming function-
This one has been generated using content_format, that does not display-
<div id="gmap-gmap_33_field_test_location_map-gmap1" style="width: 260px; height: 200px;" class="gmap-control gmap-gmapgmap gmap-map gmap-gmap_33_field_test_location_map-gmap"></div>
<script type="text/javascript">Drupal.extend({ settings: { "gmap": { "gmap_33_field_test_location_map": { "width": "260px", "height": "200px", "zoom": 14, "controltype": "Small", "align": "None", "maptype": "Map", "line_colors": [ "#00cc00", "#ff0000", "#0000ff" ], "behavior": { "locpick": false, "nodrag": 0, "nokeyboard": 1, "nomousezoom": 0, "autozoom": 0, "dynmarkers": 0, "overview": 1, "notype": 0, "collapsehack": 1 }, "markermode": "0", "field_name": "field_test_location_map", "type": "gmap_cck", "required": "0", "multiple": "0", "db_storage": "0", "alignment": "Right", "gpx": null, "gpx_src": null, "marker_noderef": "", "widget": { "label": "test_location_map" }, "type_name": "mytesttype", "id": "gmap_33_field_test_location_map", "querypath": "http://myserver/map/query", "longitude": "-88.10149", "latitude": "41.693761" } } } });</script>
####################################################
####################################################
####################################################
####################################################
And this one has been generated using gmap_cck_field_formatter() and the map shows up in this case-
<div id="gmap-gmap_33_f-gmap0" style="width: 300px; height: 200px;" class="gmap-control gmap-gmapgmap gmap-map gmap-gmap_33_f-gmap"></div>
<script type="text/javascript">Drupal.extend({ settings: { "gmap": { "gmap_33_f": { "width": "300px", "height": "200px", "zoom": 14, "controltype": "Small", "align": "None", "maptype": "Map", "line_colors": [ "#00cc00", "#ff0000", "#0000ff" ], "behavior": { "locpick": false, "nodrag": 0, "nokeyboard": 1, "nomousezoom": 0, "autozoom": 0, "dynmarkers": 0, "overview": 1, "notype": 0, "collapsehack": 1 }, "markermode": "0", "id": "gmap_33_f", "querypath": "http://myserver/map/query", "longitude": "-88.10149", "latitude": "41.693761" } } } });</script>
This one seem to ignore custom size defined for the field. Instead it takes default size information and probably other properties as well from gmap module.
#11
result of $field = content_fields('field_test_location_map');
Array ( [field_name] => field_test_location_map [type] => gmap_cck [required] => 0 [multiple] => 0 [db_storage] => 0 [maptype] => Map [controltype] => Small [width] => 260px [height] => 200px [alignment] => Right [zoom] => 14 [latlong] => 41.693761,-88.10149 [gpx] => [gpx_src] => [marker_noderef] => [widget] => Array ( [label] => test_location_map ) [type_name] => mytesttype )#12
ray,
Let me know if you would like me to try out few things.
#13
Try to use http://drupal.org/project/nodeasblock
Can't do debugging custom code here, that does not work.