public function GeoCodeAddressForm::buildForm in IP Geolocation Views & Maps 8
Geocode, using the Geocoder API, the submitted street address.
Stores the geocoded lat/long on the session. Modules may implement their own variations by implementing hook_form_alter() and appending their own handler to $form['#submit'].
Parameters
array $form: A form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form's current state.
Overrides FormInterface::buildForm
File
- src/
Form/ GeoCodeAddressForm.php, line 84
Class
- GeoCodeAddressForm
- Form to reverse geocode a address to latitud and Longitude.
Namespace
Drupal\ip_geoloc\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Migration comment: Part of ip_geoloc_set_location_form definition.
$config = $this->configFactory
->get('ip_geoloc.settings');
$location = $this->api
->getVisitorLocation();
$is_address_editable = $config
->get('ip_geoloc_visitor_address_editable') ? $config
->get('ip_geoloc_visitor_address_editable') : TRUE;
$form['street_address'] = [
'#type' => 'textfield',
'#title' => t('Current approximate address'),
'#default_value' => isset($location['formatted_address']) ? $location['formatted_address'] : '',
'#disabled' => !$is_address_editable,
];
if ($is_address_editable) {
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Refine'),
'#button_type' => 'primary',
];
}
$form['#attributes']['class'][] = 'ip-geoloc-address';
$form['#attached']['library'][] = 'ip_geoloc/client_css';
return $form;
}