You are here

protected static function GeofieldDms::processComponent in Geofield 8

Helper function to generate each coordinate component form element.

Parameters

array $element: The form element.

string $type: The component type.

array $options: The component options.

array $default_value: The component default value array.

1 call to GeofieldDms::processComponent()
GeofieldDms::dmsProcess in src/Element/GeofieldDms.php
Generates the Geofield DMS form element.

File

src/Element/GeofieldDms.php, line 105

Class

GeofieldDms
Provides a Geofield DMS form element.

Namespace

Drupal\geofield\Element

Code

protected static function processComponent(array &$element, $type, array $options, array $default_value) {
  $element[$type] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
  ];
  $element[$type]['orientation'] = [
    '#type' => 'select',
    '#title' => '',
    '#options' => $options,
    '#multiple' => FALSE,
    '#required' => !empty($element['#required']) ? $element['#required'] : FALSE,
    '#default_value' => !empty($default_value) ? $default_value['orientation'] : '',
    '#attributes' => [
      'class' => [
        'geofield-' . $type . '-orientation',
        'container-inline',
      ],
      'style' => [
        'min-width: 6em',
      ],
    ],
  ];
  $element[$type]['degrees'] = [
    '#type' => 'number',
    '#min' => 0,
    '#step' => 1,
    '#max' => 180,
    '#title' => '',
    '#required' => !empty($element['#required']) ? $element['#required'] : FALSE,
    '#default_value' => !empty($default_value) ? $default_value['degrees'] : '',
    '#suffix' => '°',
    '#attributes' => [
      'class' => [
        'geofield-' . $type . '-degrees',
        'container-inline',
      ],
    ],
  ];
  $element[$type]['minutes'] = [
    '#type' => 'number',
    '#min' => 0,
    '#max' => 59,
    '#step' => 1,
    '#title' => '',
    '#required' => !empty($element['#required']) ? $element['#required'] : FALSE,
    '#default_value' => !empty($default_value) ? $default_value['minutes'] : '',
    '#suffix' => '\'',
    '#attributes' => [
      'class' => [
        'geofield-' . $type . '-minutes',
        'container-inline',
      ],
    ],
  ];
  $element[$type]['seconds'] = [
    '#type' => 'number',
    '#min' => 0,
    '#max' => 59,
    '#step' => 1,
    '#title' => '',
    '#required' => !empty($element['#required']) ? $element['#required'] : FALSE,
    '#default_value' => !empty($default_value) ? $default_value['seconds'] : '',
    '#suffix' => '"',
    '#attributes' => [
      'class' => [
        'geofield-' . $type . '-seconds',
        'container-inline',
      ],
    ],
  ];
}