You are here

public function Geocoder::getForm in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/geolocation/LocationInput/Geocoder.php \Drupal\geolocation\Plugin\geolocation\LocationInput\Geocoder::getForm()

Get center form.

Parameters

int $center_option_id: LocationInput option ID.

array $center_option_settings: The current feature settings.

mixed $context: Context like field formatter, field widget or view.

array $default_value: Optional form values.

Return value

array Form.

Overrides LocationInputBase::getForm

File

src/Plugin/geolocation/LocationInput/Geocoder.php, line 180

Class

Geocoder
Location based proximity center.

Namespace

Drupal\geolocation\Plugin\geolocation\LocationInput

Code

public function getForm($option_id, array $option_settings, $context = NULL, array $default_value = NULL) {
  $form = parent::getForm($option_id, $option_settings, $context, $default_value);
  if (empty($form['coordinates'])) {
    return $form;
  }
  $option_settings = $this
    ->getSettings($option_settings);
  $identifier = uniqid($option_id);
  $form['coordinates']['#attributes'] = [
    'class' => [
      $identifier,
      'location-input-geocoder',
    ],
  ];
  $form['geocoder'] = [
    '#type' => 'container',
    '#attached' => [
      'library' => [
        'geolocation/location_input.geocoder',
      ],
      'drupalSettings' => [
        'geolocation' => [
          'locationInput' => [
            'geocoder' => [
              [
                'identifier' => $identifier,
                'autoSubmit' => $option_settings['auto_submit'],
                'hideForm' => $option_settings['hide_form'],
              ],
            ],
          ],
        ],
      ],
    ],
  ];

  /** @var \Drupal\geolocation\GeocoderInterface $geocoder_plugin */
  $geocoder_plugin = $this->geocoderManager
    ->getGeocoder($option_settings['plugin_id'], $option_settings['settings']);
  $geocoder_plugin
    ->formAttachGeocoder($form['geocoder'], $identifier);
  return $form;
}