function addressfield_staticmap_block_view in Address Field Static Map 7
Implements hook_block_view().
File
- ./
addressfield_staticmap.module, line 57 - Main file for the addressfield static map module.
Code
function addressfield_staticmap_block_view($delta = '') {
$block = array();
$deltas = array(
'addressfield_staticmap',
'addressfield_staticmap_alt',
);
if (!in_array($delta, $deltas)) {
return $block;
}
$index = array_search($delta, $deltas);
// Check if the address field name is configured.
$field_names = variable_get('addressfield_staticmap_field_names', '');
if (empty($field_names) || !array_filter($field_names)) {
return $block;
}
$entity = menu_get_object();
if (empty($entity)) {
return $block;
}
$block['subject'] = t('Address Field Static Map');
$block['content'] = '';
// Do this for each of the enabled address fields.
foreach ($field_names as $field_name) {
if (empty($entity->base_type)) {
continue;
}
$fields = field_get_items($entity->base_type, $entity, $field_name, $entity->language);
if (empty($fields)) {
continue;
}
// Fetch configuration variables.
$api = variable_get('addressfield_staticmap_api_' . $index, 'google_maps');
// Configure base settings.
$settings = array(
'zoom' => variable_get('addressfield_staticmap_gmap_zoom_' . $index, 14),
'size' => variable_get('addressfield_staticmap_gmap_size_' . $index, ''),
'scroll_lock' => variable_get('addressfield_staticmap_scroll_lock_' . $index, FALSE),
'maptype' => variable_get('addressfield_staticmap_gmap_type_' . $index, 'roadmap'),
'scale' => variable_get('addressfield_staticmap_scale_' . $index, 1),
'index' => $index,
);
foreach ($fields as $id => $data) {
$data_cleaned = array_filter($data);
// If only the country is set, skip this (for some reason the country
// value becomes mandatory if you limit the list).
if (isset($data_cleaned['country']) && count($data_cleaned) <= 1) {
continue;
}
$address = addressfield_staticmap_clean_address($data);
// Display the address if the checkbox is set.
if (variable_get('addressfield_staticmap_gmap_show_address_' . $index, FALSE)) {
$settings['text_address'] = _addressfield_staticmap_render_address($data);
}
// Display the info window if the checkbox is set.
$settings['info_window'] = variable_get('addressfield_staticmap_gmap_show_info_window_' . $index, FALSE);
// Use Google Maps.
if ($api == 'google_maps') {
$settings['icon_url'] = variable_get('addressfield_staticmap_gmap_icon_url_' . $index, '');
$settings['icon_url'] = empty($settings['icon_url']) ? 'color:green' : 'icon:' . $settings['icon_url'];
$settings['premier'] = variable_get('addressfield_staticmap_premier_' . $index, '');
$settings['api_key'] = variable_get('addressfield_staticmap_api_key_' . $index, '');
$settings['client_id'] = variable_get('addressfield_staticmap_premium_client_id_' . $index, '');
$settings['crypto_key'] = variable_get('addressfield_staticmap_premium_crypto_key_' . $index, '');
$block['content'] .= _addressfield_static_map_render_google_maps_image($address, $settings, $entity);
}
elseif ($api == 'google_maps_api') {
$settings['icon_url'] = variable_get('addressfield_staticmap_gmap_icon_url_' . $index, '');
$settings['icon_url'] = empty($settings['icon_url']) ? 'color:green' : 'icon:' . $settings['icon_url'];
$settings['premier'] = variable_get('addressfield_staticmap_premier_' . $index, '');
$settings['api_key'] = variable_get('addressfield_staticmap_api_key_' . $index, '');
$settings['client_id'] = variable_get('addressfield_staticmap_premium_client_id_' . $index, '');
$settings['crypto_key'] = variable_get('addressfield_staticmap_premium_crypto_key_' . $index, '');
$block['content'] .= _addressfield_static_map_render_google_maps($address, $settings, $entity);
}
elseif ($api == 'google_maps_embed') {
$settings['icon_url'] = variable_get('addressfield_staticmap_gmap_icon_url_' . $index, '');
$settings['icon_url'] = empty($settings['icon_url']) ? 'color:green' : 'icon:' . $settings['icon_url'];
$settings['premier'] = variable_get('addressfield_staticmap_premier_' . $index, '');
$settings['api_key'] = variable_get('addressfield_staticmap_api_key_' . $index, '');
$settings['client_id'] = variable_get('addressfield_staticmap_premium_client_id_' . $index, '');
$settings['crypto_key'] = variable_get('addressfield_staticmap_premium_crypto_key_' . $index, '');
$block['content'] .= _addressfield_embed_map_render_google_maps($address, $settings, $entity);
}
elseif ($api == 'mapquest') {
$settings['api_key'] = variable_get('addressfield_staticmap_api_key_' . $index, '');
$block['content'] .= _addressfield_static_map_render_mapquest_image($address, $settings);
}
}
}
return $block;
}