public function MarkerClusterer::validateSettingsForm in Geolocation Field 8.3
Same name and namespace in other branches
- 8.2 modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/MarkerClusterer.php \Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature\MarkerClusterer::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/ MarkerClusterer.php, line 101
Class
- MarkerClusterer
- Provides marker clusterer.
Namespace
Drupal\geolocation_google_maps\Plugin\geolocation\MapFeatureCode
public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents) {
$marker_clusterer_styles = $values['styles'];
if (!empty($marker_clusterer_styles)) {
$style_parents = $parents;
$style_parents[] = 'styles';
if (!is_string($marker_clusterer_styles)) {
$form_state
->setErrorByName(implode('][', $style_parents), $this
->t('Please enter a JSON string as style.'));
}
$json_result = json_decode($marker_clusterer_styles);
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.'));
}
}
if (!is_numeric($values['grid_size'])) {
$form_state
->setErrorByName(implode('][', $parents) . '][grid_size', $this
->t('Grid size must be a number.'));
}
if (!is_numeric($values['minimum_cluster_size'])) {
$form_state
->setErrorByName(implode('][', $parents) . '][minimum_cluster_size', $this
->t('Minimum cluster size must be a number.'));
}
}