You are here

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

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

Form element json format validation handler.

File

src/LeafletSettingsElementsTrait.php, line 1054

Class

LeafletSettingsElementsTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\leaflet

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));
  }
}