You are here

function addressfield_autocomplete_field_widget_settings_form in Addressfield Autocomplete 7

Implements hook_field_widget_settings_form().

File

./addressfield_autocomplete.module, line 101
The Addressfield Autocomplete module code.

Code

function addressfield_autocomplete_field_widget_settings_form($field, $instance) {
  $widget = $instance['widget'];
  if ($widget['type'] == 'addressfield_autocomplete') {
    $settings = $widget['settings'];
    $types = array(
      'geocode',
      'establishment',
      '(regions)',
      '(cities)',
    );
    $form['available_countries'] = array(
      '#type' => 'select',
      '#multiple' => TRUE,
      '#title' => t('Available countries'),
      '#description' => t('If no countries are selected, all countries will be available. If one country is selected the google autocomplete search will be restricted to just that one specific country.'),
      '#options' => _addressfield_country_options_list(),
      '#default_value' => $settings['available_countries'],
      '#weight' => 1,
    );
    $form['default_country'] = array(
      '#type' => 'select',
      '#title' => t('Default country'),
      '#options' => _addressfield_country_options_list(),
      '#default_value' => $settings['default_country'],
      '#empty_value' => '',
      '#weight' => 1,
    );
    $form['format_handlers'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Format handlers'),
      '#options' => addressfield_format_plugins_options(),
      '#default_value' => $settings['format_handlers'],
      '#weight' => 1,
    );
    $form['map'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show map'),
      '#description' => t('Uncheck this box to remove the map, if you want draggable markers this must be selected.'),
      '#default_value' => $settings['map'],
      '#weight' => 2,
    );
    $form['reveal'] = array(
      '#type' => 'checkbox',
      '#title' => t('Reveal widget'),
      '#description' => t('Reveal the addressfield widget after the geocomplete has returned an address.'),
      '#default_value' => $settings['reveal'],
      '#weight' => 2,
    );
    $form['manual_text'] = array(
      '#type' => 'textfield',
      '#title' => t('Manual text'),
      '#description' => t('The text to display for the link to enter an address manually.'),
      '#default_value' => $settings['manual_text'],
      '#weight' => 3,
      '#states' => array(
        'visible' => array(
          ':input[name="instance[widget][settings][reveal]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['visible_markers'] = array(
      '#type' => 'checkbox',
      '#title' => t('Visible markers'),
      '#description' => t('Choose whether or not the markers should be shown.'),
      '#default_value' => $settings['visible_markers'],
      '#weight' => 4,
    );
    $form['draggable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Draggable markers'),
      '#description' => t('Alter the location of the pointer on the map. Will only work if show map and visible markers are checked.'),
      '#default_value' => $settings['draggable'],
      '#weight' => 4,
    );
    $form['reverse_geocode'] = array(
      '#type' => 'checkbox',
      '#title' => t('Reverse geocode'),
      '#description' => t('Enable this to update the address when the marker is moved.'),
      '#default_value' => $settings['reverse_geocode'],
      '#weight' => 4,
    );
    $form['html5_geocode'] = array(
      '#type' => 'checkbox',
      '#title' => t('HTML5 geocode'),
      '#description' => t('Enable HTML5 browser location share when user is entering a manual address.'),
      '#default_value' => $settings['html5_geocode'],
      '#weight' => 4,
    );
    $form['types'] = array(
      '#type' => 'select',
      '#title' => t('Place types'),
      '#description' => t('The autocomplete service will return results that match any of the specified types, default is geocode.'),
      '#options' => drupal_map_assoc($types),
      '#default_value' => $settings['types'],
      '#weight' => 4,
    );
    return $form;
  }
  $settings = $instance['widget']['settings'];
  $fields = field_info_instances($instance['entity_type'], $instance['bundle']);
  $options = array();
  $geophp_installed = module_exists('geophp');
  foreach ($fields as $field) {
    if ($field['widget']['type'] == 'addressfield_autocomplete') {
      $options[$field['field_name']] = $field['label'];
    }
  }
  $form['addressfield_autocomplete_field'] = array(
    '#type' => 'select',
    '#title' => t('Fill from addressfield autocomplete'),
    '#empty_option' => t('- Select -'),
    '#default_value' => $settings['addressfield_autocomplete_field'],
    '#options' => $options,
    '#description' => t('Select which address autocomplete field to pick from.'),
    '#required' => TRUE,
    '#disabled' => !$geophp_installed,
  );
  $items = array(
    'Matched with each input (e.g. One POINT for each address field)',
    'Aggregated into a single MULTIPOINT geofield (e.g. One MULTIPOINT polygon from multiple address fields)',
  );
  $form['delta_handling'] = array(
    '#type' => 'select',
    '#title' => t('Multi-value input handling'),
    '#description' => t('Should geometries from multiple inputs be: !list', array(
      '!list' => theme('item_list', array(
        'items' => $items,
      )),
    )),
    '#default_value' => $settings['delta_handling'],
    '#options' => array(
      'default' => 'Match Multiples (default)',
      'm_to_s' => 'Multiple to Single',
    ),
    '#required' => TRUE,
    '#disabled' => !$geophp_installed,
  );
  if (!$geophp_installed) {
    form_set_error('addressfield_autocomplete_field', t('You need to have installed the <a href="@project_page">geophp</a> module before you can use this feature.', array(
      '@project_page' => 'http://drupal.org/project/geophp',
    )));
  }
  return $form;
}