You are here

public static function LeafletSettingsElementsTrait::validateGeocoderProviders in Leaflet 2.0.x

Same name and namespace in other branches
  1. 8 src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::validateGeocoderProviders()
  2. 2.1.x src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::validateGeocoderProviders()

Validates the Geocoder Providers element.

Parameters

array $element: The form element to build.

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

File

src/LeafletSettingsElementsTrait.php, line 1073

Class

LeafletSettingsElementsTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\leaflet

Code

public static function validateGeocoderProviders(array $element, FormStateInterface &$form_state) {
  $form_state_input = $form_state
    ->getUserInput();
  if (isset($form_state_input['style_options'])) {
    $geocoder_control = $form_state_input['style_options']['geocoder']['control'];
  }
  if (isset($form_state_input['fields'])) {
    $geocoder_control = $form_state_input['fields'][$element['#array_parents'][1]]['settings_edit_form']['settings']['geocoder']['control'];
  }
  if (isset($geocoder_control) && $geocoder_control) {
    $providers = is_array($element['#value']) ? array_filter($element['#value'], function ($value) {
      return isset($value['checked']) && TRUE == $value['checked'];
    }) : [];
    if (empty($providers)) {
      $form_state
        ->setError($element, t('The Geocode Origin option needs at least one geocoder plugin selected.'));
    }
  }
}