You are here

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

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

Form element validation handler for the Map Max Zoom level.

File

src/LeafletSettingsElementsTrait.php, line 1034

Class

LeafletSettingsElementsTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\leaflet

Code

public static function maxZoomLevelValidate($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 max zoom level.
  $min_zoom = $values['minZoom'];
  $max_zoom = $element['#value'];
  if ($max_zoom && $max_zoom <= $min_zoom) {
    $form_state
      ->setError($element, t('The Max Zoom level should be above the Minimum Zoom level.'));
  }
}