public static function LeafletSettingsElementsTrait::zoomLevelValidate in Leaflet 8
Same name and namespace in other branches
- 2.1.x src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::zoomLevelValidate()
- 2.0.x src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::zoomLevelValidate()
Form element validation handler for a Map Zoom level.
File
- src/
LeafletSettingsElementsTrait.php, line 927
Class
- LeafletSettingsElementsTrait
- Class GeofieldMapFieldTrait.
Namespace
Drupal\leafletCode
public static function zoomLevelValidate($element, FormStateInterface &$form_state) {
// Get to the actual values in a form tree.
$parents = $element['#parents'];
$values = $form_state
->getValues();
for ($i = 0; $i < count($parents) - 1; $i++) {
$values = $values[$parents[$i]];
}
// Check the initial map zoom level.
$zoom = $element['#value'];
$min_zoom = $values['minZoom'];
$max_zoom = $values['maxZoom'];
if ($zoom < $min_zoom || $zoom > $max_zoom) {
$form_state
->setError($element, t('The @zoom_field should be between the Minimum and the Maximum Zoom levels.', [
'@zoom_field' => $element['#title'],
]));
}
}