You are here

public static function GeocodeOrigin::jsonValidate in Geocoder 8.2

Form element json format validation handler.

File

src/Plugin/GeofieldProximitySource/GeocodeOrigin.php, line 372

Class

GeocodeOrigin
Defines 'Geocode Origin (with Autocomplete option)' proximity source plugin.

Namespace

Drupal\geocoder\Plugin\GeofieldProximitySource

Code

public static function jsonValidate($element, FormStateInterface &$form_state) {
  $element_values_array = JSON::decode($element['#value']);

  // Check the jsonValue.
  if (!empty($element['#value']) && $element_values_array == NULL) {
    $form_state
      ->setError($element, t('The @field field is not valid Json Format.', [
      '@field' => $element['#title'],
    ]));
  }
  elseif (!empty($element['#value'])) {
    $form_state
      ->setValueForElement($element, [
      'options' => $element_values_array,
    ]);
  }
}