You are here

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

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

Form element validation handler for a Map Zoom level.

File

src/LeafletSettingsElementsTrait.php, line 1013

Class

LeafletSettingsElementsTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\leaflet

Code

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'],
    ]));
  }
}