You are here

public static function GeofieldElementBase::elementValidate in Geofield 8

Validates a Geofield generic component based form 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.

1 call to GeofieldElementBase::elementValidate()
GeofieldBounds::boundsValidate in src/Element/GeofieldBounds.php
Validates a Geofield bounds element.

File

src/Element/GeofieldElementBase.php, line 71

Class

GeofieldElementBase
Provides a base class for Geofield Form elements.

Namespace

Drupal\geofield\Element

Code

public static function elementValidate(array &$element, FormStateInterface $form_state, array &$complete_form) {
  $error_label = isset($element['#error_label']) ? $element['#error_label'] : $element['#title'];
  foreach (static::getComponents() as $key => $component) {
    if (!empty($element[$key]['#value']) && !is_numeric($element[$key]['#value'])) {
      $form_state
        ->setError($element[$key], t('@title: @component_title is not valid.', [
        '@title' => $error_label,
        '@component_title' => $component['title'],
      ]));
    }
    elseif (is_numeric($element[$key]['#value']) && abs($element[$key]['#value']) > $component['range']) {
      $form_state
        ->setError($element[$key], t('@title: @component_title is out of bounds (@bounds).', [
        '@title' => $error_label,
        '@component_title' => $component['title'],
        '@bounds' => '+/- ' . $component['range'],
      ]));
    }
  }
}