public function SetLocationForm::buildForm in IP Geolocation Views & Maps 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ SetLocationForm.php, line 61
Class
- SetLocationForm
- Peding doc.
Namespace
Drupal\ip_geoloc\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Migration comment: Part of ip_geoloc_set_location_form definition.
$ip_geoloc_config = $this
->config('ip_geoloc.settings');
$has_find_visitor = $ip_geoloc_config
->get('ip_geoloc_visitor_find') ? $ip_geoloc_config
->get('ip_geoloc_visitor_find') : TRUE;
$is_address_editable = $ip_geoloc_config
->get('ip_geoloc_visitor_address_editable') ? $ip_geoloc_config
->get('ip_geoloc_visitor_address_editable') : TRUE;
$geo_vocabulary_id = $ip_geoloc_config
->get('ip_geoloc_geo_vocabulary_id') ? $ip_geoloc_config
->get('ip_geoloc_geo_vocabulary_id') : 0;
if (!$has_find_visitor && !$is_address_editable && !$geo_vocabulary_id) {
$this->messenger
->addError($this
->t('You should select at least one of the three widgets available for the "Set my location" block.'));
return $form;
}
$location = $this->api
->getVisitorLocation();
$form['#attributes']['id'] = $ajax_wrapper_id = drupal_html_id('set-location-form');
if ($has_find_visitor) {
_ip_geoloc_set_my_location_add_find_me($form, $ajax_wrapper_id);
}
$options = _ip_geoloc_set_my_location_add_selector($form, $location, $is_address_editable, $geo_vocabulary_id);
$is_reverse_geocode = $has_find_visitor && $ip_geoloc_config
->get('ip_geoloc_visitor_reverse_geocode') ? $ip_geoloc_config
->get('ip_geoloc_visitor_reverse_geocode') : TRUE;
if ($is_reverse_geocode || $is_address_editable) {
_ip_geoloc_set_my_location_add_address($form, $location);
}
if ($geo_vocabulary_id) {
_ip_geoloc_set_my_location_add_region($form, $location, $geo_vocabulary_id);
}
_ip_geoloc_set_my_location_add_logic($form, $location, $options, $is_address_editable, $geo_vocabulary_id);
if ($is_address_editable || $geo_vocabulary_id) {
$form['submit_address'] = [
'#type' => 'submit',
'#value' => t('Go'),
'#submit' => [
'_ip_geoloc_process_go_to_submit',
],
'#weight' => 15,
];
}
$form['#attributes']['class'][] = 'ip-geoloc-address';
$form['#attached']['library'][] = 'ip_geoloc/ip_geoloc.client';
return $form;
}