You are here

public static function GeofieldMapFieldTrait::maxZoomLevelValidate in Geofield Map 8

Form element validation handler for the Map Max Zoom level.

File

src/GeofieldMapFieldTrait.php, line 241

Class

GeofieldMapFieldTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\geofield_map

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['min'];
  $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.'));
  }
}