You are here

public static function GeofieldMapFieldTrait::jsonValidate in Geofield Map 8

Form element json format validation handler.

File

src/GeofieldMapFieldTrait.php, line 278

Class

GeofieldMapFieldTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\geofield_map

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, JSON::encode($element_values_array));
  }
}