You are here

function geofield_field_formatter_settings_form in Geofield 7

Same name and namespace in other branches
  1. 7.2 geofield.formatters.inc \geofield_field_formatter_settings_form()

Implements hook_field_formatter_settings_form().

File

./geofield.formatters.inc, line 103
Drupal field formatter hooks and helper functions.

Code

function geofield_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];

  // Map preset formatter
  if ($display['type'] == 'geofield_openlayers' && module_exists('openlayers')) {

    // Get preset options, filtered to those which have the GeoField placeholder layer
    $presets = openlayers_presets();
    $preset_options = array();
    foreach ($presets as $preset) {
      if (in_array('geofield_formatter', $preset->data['layers'])) {
        $preset_options[$preset->name] = $preset->title;
      }
    }
    $element['map_preset'] = array(
      '#title' => t('OpenLayers Preset'),
      '#type' => 'select',
      '#default_value' => $settings['map_preset'] ? $settings['map_preset'] : 'geofield_formatter_map',
      '#required' => TRUE,
      '#options' => $preset_options,
      '#description' => t('Select which OpenLayers map you would like to use. Only maps which have the geofield placeholder layer may be selected. If your preferred map is not here, add the geofield placeholder layer to it first.'),
    );
  }
  $data_options = _geofield_formatter_settings_data_options($display['type']);
  $element['data'] = array(
    '#title' => t('Data options'),
    '#type' => 'select',
    '#default_value' => $settings['data'] ? $settings['data'] : 'full',
    '#required' => TRUE,
    '#options' => $data_options,
  );
  if ($display['type'] == 'geofield_latlon' || $display['type'] == 'geofield_lat' || $display['type'] == 'geofield_lon') {
    $format_options = _geofield_formatter_settings_format_options($display['type']);
    $element['format'] = array(
      '#title' => t('Format'),
      '#type' => 'select',
      '#default_value' => $settings['format'] ? $settings['format'] : 'decimal_degrees',
      '#required' => TRUE,
      '#options' => $format_options,
    );
  }
  if ($display['type'] == 'geofield_latlon') {
    $element['labels'] = array(
      '#title' => t('Display Labels'),
      '#type' => 'checkbox',
      '#default_value' => $settings['labels'],
    );
  }
  if ($display['type'] == 'geofield_def_list' || $display['type'] == 'geofield_description') {
    $element['address'] = array(
      '#title' => t('Include reverse-geocoded address'),
      '#type' => 'checkbox',
      '#default_value' => $settings['address'],
    );
  }
  return $element;
}