public function GoogleMapsDisplayTrait::validateGoogleMapsSettingsForm in Geolocation Field 8
Validate the form elements defined above.
Parameters
array $form: Values to validate.
\Drupal\Core\Form\FormStateInterface $form_state: Current Formstate.
string|null $prefix: Form state prefix if needed.
1 call to GoogleMapsDisplayTrait::validateGoogleMapsSettingsForm()
- CommonMap::validateOptionsForm in src/
Plugin/ views/ style/ CommonMap.php - Validate the options form.
File
- src/
GoogleMapsDisplayTrait.php, line 477
Class
- GoogleMapsDisplayTrait
- Class GoogleMapsDisplayTrait.
Namespace
Drupal\geolocationCode
public function validateGoogleMapsSettingsForm(array $form, FormStateInterface $form_state, $prefix = NULL) {
if ($prefix) {
$values = $form_state
->getValues();
if (!empty($values[$prefix])) {
$values = $values[$prefix];
$prefix = $prefix . '][';
}
else {
return;
}
}
else {
$values = $form_state
->getValues();
}
$json_style = $values['google_map_settings']['style'];
if (!empty($json_style)) {
if (!is_string($json_style)) {
$form_state
->setErrorByName($prefix . 'google_map_settings][style', $this
->t('Please enter a JSON string as style.'));
}
$json_result = json_decode($json_style);
if ($json_result === NULL) {
$form_state
->setErrorByName($prefix . 'google_map_settings][style', $this
->t('Decoding style JSON failed. Error: %error.', [
'%error' => json_last_error(),
]));
}
elseif (!is_array($json_result)) {
$form_state
->setErrorByName($prefix . 'google_map_settings][style', $this
->t('Decoded style JSON is not an array.'));
}
}
}