You are here

public static function GeofieldMapFieldTrait::zoomLevelValidate in Geofield Map 8

Form element validation handler for a Map Zoom level.

File

src/GeofieldMapFieldTrait.php, line 220

Class

GeofieldMapFieldTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\geofield_map

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['min'];
  $max_zoom = $values['max'];
  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'],
    ]));
  }
}