public static function GeofieldDms::dmsProcess in Geofield 8
Generates the Geofield DMS form element.
Parameters
array $element: An associative array containing the properties and children of the element. Note that $element must be taken by reference here, so processed child elements are taken over into $form_state.
\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/ GeofieldDms.php, line 48
Class
- GeofieldDms
- Provides a Geofield DMS form element.
Namespace
Drupal\geofield\ElementCode
public static function dmsProcess(array &$element, FormStateInterface $form_state, array &$complete_form) {
$element['#tree'] = TRUE;
$element['#input'] = TRUE;
$default_value = [];
if (!empty($element['#default_value']['lon']) && !empty($element['#default_value']['lat'])) {
$default_value = DmsConverter::decimalToDms($element['#default_value']['lon'], $element['#default_value']['lat']);
}
$options = [
'lat' => [
'N' => t('North'),
'S' => t('South'),
],
'lon' => [
'E' => t('East'),
'W' => t('West'),
],
];
foreach ($options as $type => $option) {
$component_default = !empty($default_value) ? $default_value
->get($type) : [];
self::processComponent($element, $type, $option, $component_default);
}
unset($element['#value']);
// Set this to false always to prevent notices.
$element['#required'] = FALSE;
return $element;
}