public static function GeolocationInput::processGeolocation in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 src/Element/GeolocationInput.php \Drupal\geolocation\Element\GeolocationInput::processGeolocation()
Processes the geolocation form element.
Parameters
array $element: The form element to process.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
Return value
array The processed element.
File
- src/
Element/ GeolocationInput.php, line 59
Class
- GeolocationInput
- Provides a render element to display a geolocation map.
Namespace
Drupal\geolocation\ElementCode
public static function processGeolocation(array &$element, FormStateInterface $form_state, array &$complete_form) {
$default_field_values = [
'lat' => '',
'lng' => '',
];
if ($element['#defaults_loaded'] && isset($element['#value']['lat']) && isset($element['#value']['lng'])) {
$default_field_values = [
'lat' => $element['#value']['lat'],
'lng' => $element['#value']['lng'],
];
}
elseif (!empty($element['#default_value']) && isset($element['#default_value']['lat']) && isset($element['#default_value']['lng'])) {
$default_field_values = [
'lat' => $element['#default_value']['lat'],
'lng' => $element['#default_value']['lng'],
];
}
$element['lat'] = [
'#type' => 'textfield',
'#title' => t('Latitude'),
'#default_value' => $default_field_values['lat'],
'#attributes' => [
'class' => [
'geolocation-input-latitude',
'geolocation-input-latitude',
],
],
];
$element['lng'] = [
'#type' => 'textfield',
'#title' => t('Longitude'),
'#default_value' => $default_field_values['lng'],
'#attributes' => [
'class' => [
'geolocation-input-longitude',
],
],
];
if (empty($element['#wrapper_attributes'])) {
$element['#wrapper_attributes'] = [];
}
$element['#wrapper_attributes'] = array_merge_recursive($element['#wrapper_attributes'], [
'class' => [
'geolocation-input',
],
]);
return $element;
}