function geocoder_field_field_formatter_view in Geocoder 7.2
Implements hook_field_formatter_view().
File
- modules/
geocoder_field/ geocoder_field.module, line 777
Code
function geocoder_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$settings = $display['settings'];
$geocoder_handlers = array_filter($settings['geocoder_handlers'], function ($v) {
return (bool) $v['enabled'];
});
uasort($geocoder_handlers, function ($a, $b) {
if ($a['enabled'] > $b['enabled']) {
return -1;
}
elseif ($a['enabled'] < $b['enabled']) {
return 1;
}
if ($a['weight'] < $b['weight']) {
return -1;
}
elseif ($a['weight'] > $b['weight']) {
return 1;
}
return 0;
});
$geocoder_handlers = array_keys($geocoder_handlers);
switch ($display['type']) {
case 'geocoder_reverse':
foreach ($items as $delta => $item) {
if ($geocoder = reverse($geocoder_handlers, $item['lat'], $item['lon'])) {
$geocoder = _geocoder_field_geocoder_to_addressfield($geocoder, $field, $display, $instance);
$context = array(
'mode' => 'render',
'field' => $field,
'instance' => $instance,
'langcode' => $langcode,
'delta' => $delta,
);
$element[$delta] = addressfield_generate($geocoder, array_values($settings['format_handlers']), $context);
}
}
break;
}
return $element;
}