You are here

public function ControlDirections::getDirectionsControlForm in Geolocation Field 8.3

Directions control form.

Parameters

array $settings: Settings.

Return value

array Directions form.

1 call to ControlDirections::getDirectionsControlForm()
ControlDirections::alterMap in modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ControlDirections.php
Alter render array.

File

modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ControlDirections.php, line 141

Class

ControlDirections
Provides Directions Service.

Namespace

Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature

Code

public function getDirectionsControlForm(array $settings, array $context = []) {
  $form = [
    '#type' => 'form',
    '#form_id' => 'directions_control',
    '#attributes' => [
      'id' => Html::getUniqueId('geolocation-google-maps-directions-controls'),
      'class' => [
        'geolocation-google-maps-directions-controls',
      ],
    ],
  ];
  if ($settings['origin_source'] == 'exposed' || $settings['destination_source'] == 'exposed') {
    $form['#attributes']['class'][] = 'geolocation-google-maps-directions-controls-block';
  }
  switch ($settings['origin_source']) {
    case 'exposed':
      $form['origin'] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Origin'),
        '#size' => 24,
        '#name' => 'geolocation-google-maps-directions-controls-origin',
        '#description' => $this
          ->t('Enter an address like "Chicago, IL".'),
        '#description_display' => 'after',
      ];
      break;
    case 'static':
      $form['origin'] = [
        '#type' => 'hidden',
        '#name' => 'geolocation-google-maps-directions-controls-origin',
        '#value' => \Drupal::token()
          ->replace($settings['origin_static_value'], $context),
      ];
      break;
  }
  switch ($settings['destination_source']) {
    case 'exposed':
      $form['destination'] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Destination'),
        '#size' => 24,
        '#name' => 'geolocation-google-maps-directions-controls-destination',
        '#description' => $this
          ->t('Enter an address like "Darwin, NSW, Australia".'),
        '#description_display' => 'after',
      ];
      break;
    case 'static':
      $form['destination'] = [
        '#type' => 'hidden',
        '#name' => 'geolocation-google-maps-directions-controls-destination',
        '#value' => \Drupal::token()
          ->replace($settings['destination_static_value'], $context),
      ];
      break;
  }
  switch ($settings['travel_mode']) {
    case 'exposed':
      $form['travel_mode'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Origin'),
        '#options' => [
          'driving' => $this
            ->t('Driving'),
          'walking' => $this
            ->t('Walking'),
          'bicycling' => $this
            ->t('Bicycling'),
          'transit' => $this
            ->t('Transit'),
        ],
        '#name' => 'geolocation-google-maps-directions-controls-travel-mode',
        '#description_display' => 'after',
      ];
      break;
    default:
      $form['travel_mode'] = [
        '#type' => 'hidden',
        '#name' => 'geolocation-google-maps-directions-controls-travel-mode',
        '#value' => $settings['travel_mode'],
      ];
      break;
  }
  $form['get_directions'] = [
    '#type' => 'button',
    '#value' => $this
      ->t('Get Directions'),
  ];
  return $form;
}