function simple_gmap_field_formatter_view in Simple Google Maps 7
Implements hook_field_formatter_view().
Formats map/link fields.
File
- ./
simple_gmap.module, line 75 - Simple Google Maps module.
Code
function simple_gmap_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
global $language;
$element = array();
// Figure out what to display for each item we have here.
$embed = (int) $display['settings']['include_map'] ? TRUE : FALSE;
$static = isset($display['settings']['include_static_map']) && (int) $display['settings']['include_static_map'] ? TRUE : FALSE;
$link = (int) $display['settings']['include_link'] ? TRUE : FALSE;
$text = (int) $display['settings']['include_text'] ? TRUE : FALSE;
$height = check_plain($display['settings']['iframe_height']);
$width = check_plain($display['settings']['iframe_width']);
$static_scale = (int) check_plain($display['settings']['static_scale']);
$link_text = $link ? check_plain($display['settings']['link_text']) : '';
$zoom_level = (int) $display['settings']['zoom_level'];
$apikey = check_plain($display['settings']['apikey']);
// Figure out a language code to use. Google cannot recognize 'und'.
$lang_to_use = isset($display['settings']['langcode']) ? check_plain($display['settings']['langcode']) : 'en';
if ($lang_to_use == 'page') {
$lang_to_use = $langcode;
}
if ($lang_to_use == LANGUAGE_NONE) {
$lang_to_use = $language->language;
}
// For some reason, static gmaps accepts a different value for map type.
$static_map_types = array(
'm' => 'roadmap',
'k' => 'satellite',
'h' => 'hybrid',
'p' => 'terrain',
);
$map_type = isset($display['settings']['map_type']) ? check_plain($display['settings']['map_type']) : 'm';
// Default to standard map if not recognized.
if (!in_array($map_type, array(
'm',
'k',
'h',
'p',
))) {
$map_type = 'm';
}
foreach ($items as $delta => $item) {
$url_value = urlencode($item['value']);
$address_value = check_plain($item['value']);
$address = $text ? $address_value : '';
$element[$delta] = array(
'#theme' => 'simple_gmap_output',
'#include_map' => $embed,
'#include_static_map' => $static,
'#include_link' => $link,
'#include_text' => $text,
'#width' => $width,
'#height' => $height,
'#static_scale' => $static_scale,
'#url_suffix' => $url_value,
'#zoom' => $zoom_level,
'#link_text' => $link_text == 'use_address' ? $address_value : $link_text,
'#address_text' => $address,
'#map_type' => $map_type,
'#langcode' => $lang_to_use,
'#static_map_type' => $static_map_types[$map_type],
'#apikey' => $apikey,
);
}
return $element;
}