public function MapTypeStyle::validateSettingsForm in Geolocation Field 8.3
Same name and namespace in other branches
- 8.2 modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/MapTypeStyle.php \Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature\MapTypeStyle::validateSettingsForm()
Validate Feature Form.
Parameters
array $values: Feature values.
\Drupal\Core\Form\FormStateInterface $form_state: Form State.
array $parents: Element parents.
Overrides MapFeatureBase::validateSettingsForm
File
- modules/
geolocation_google_maps/ src/ Plugin/ geolocation/ MapFeature/ MapTypeStyle.php, line 49
Class
- MapTypeStyle
- Provides map styling support.
Namespace
Drupal\geolocation_google_maps\Plugin\geolocation\MapFeatureCode
public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents) {
$json_style = $values['style'];
if (!empty($json_style)) {
$style_parents = $parents;
$style_parents[] = 'styles';
if (!is_string($json_style)) {
$form_state
->setErrorByName(implode('][', $style_parents), $this
->t('Please enter a JSON string as style.'));
}
$json_result = json_decode($json_style);
if ($json_result === NULL) {
$form_state
->setErrorByName(implode('][', $style_parents), $this
->t('Decoding style JSON failed. Error: %error.', [
'%error' => json_last_error(),
]));
}
elseif (!is_array($json_result)) {
$form_state
->setErrorByName(implode('][', $style_parents), $this
->t('Decoded style JSON is not an array.'));
}
}
}