You are here

public static function GeofieldBounds::boundsValidate in Geofield 8

Validates a Geofield bounds element.

Parameters

array $element: The element being processed.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

File

src/Element/GeofieldBounds.php, line 66

Class

GeofieldBounds
Provides a Geofield bounds form element.

Namespace

Drupal\geofield\Element

Code

public static function boundsValidate(array &$element, FormStateInterface $form_state, array &$complete_form) {
  static::elementValidate($element, $form_state, $complete_form);
  $pairs = [
    [
      'bigger' => 'top',
      'smaller' => 'bottom',
    ],
    [
      'bigger' => 'right',
      'smaller' => 'left',
    ],
  ];
  foreach ($pairs as $pair) {
    if ($element[$pair['smaller']]['#value'] > $element[$pair['bigger']]['#value']) {
      $components = static::getComponents();
      $form_state
        ->setError($element[$pair['smaller']], t('@title: @component_bigger must be greater than @component_smaller.', [
        '@title' => $element['#title'],
        '@component_bigger' => $components[$pair['bigger']]['title'],
        '@component_smaller' => $components[$pair['smaller']]['title'],
      ]));
    }
  }
}