You are here

public function DefaultField::validateSettingsForm in Geocoder 8.3

Same name and namespace in other branches
  1. 8.2 modules/geocoder_field/src/Plugin/Geocoder/Field/DefaultField.php \Drupal\geocoder_field\Plugin\Geocoder\Field\DefaultField::validateSettingsForm()

Validates the field settings form.

Parameters

array $form: The form API form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

Overrides GeocoderFieldPluginInterface::validateSettingsForm

File

modules/geocoder_field/src/Plugin/Geocoder/Field/DefaultField.php, line 391

Class

DefaultField
Provides a default generic geocoder field plugin.

Namespace

Drupal\geocoder_field\Plugin\Geocoder\Field

Code

public function validateSettingsForm(array $form, FormStateInterface &$form_state) {
  $form_values = $form_state
    ->getValues();
  if ($form_values['method'] !== 'none' && empty($form_values['providers'])) {
    $form_state
      ->setError($form['third_party_settings']['geocoder_field']['providers'], t('The selected Geocode operation needs at least one provider.'));
  }

  // On Reverse Geocode the delta_handling should always be 'default'
  // (many to many), because the other scenario is not possible.
  if ($form_values['method'] === 'reverse_geocode') {
    $form_state
      ->setValue('delta_handling', 'default');
  }
  foreach ($form_values[$form_values['method']] as $key => $value) {
    $form_state
      ->setValue($key, $value);
  }
  $form_state
    ->unsetValue($form_values['method']);
}