You are here

public static function WebformLocationBase::validateWebformLocation in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformLocationBase.php \Drupal\webform\Element\WebformLocationBase::validateWebformLocation()

Validates location.

File

src/Element/WebformLocationBase.php, line 138

Class

WebformLocationBase
Provides a webform base element for a location element.

Namespace

Drupal\webform\Element

Code

public static function validateWebformLocation(&$element, FormStateInterface $form_state, &$complete_form) {
  $value = $element['#value'];
  if (Element::isVisibleElement($element) && !empty($element['#required']) && empty($value['lat'])) {
    $t_args = [
      '@title' => !empty($element['#title']) ? $element['#title'] : t('Location'),
    ];
    $form_state
      ->setError($element['value'], t('The @title is not valid.', $t_args));
  }
}