You are here

public static function YamlFormLocation::validateYamlFormLocation in YAML Form 8

Validates location.

File

src/Element/YamlFormLocation.php, line 160

Class

YamlFormLocation
Provides a form element for a location element.

Namespace

Drupal\yamlform\Element

Code

public static function validateYamlFormLocation(&$element, FormStateInterface $form_state, &$complete_form) {
  $value = $element['#value'];
  $has_access = !isset($element['#access']) || $element['#access'] === TRUE;
  if ($has_access && !empty($element['#required']) && empty($value['location'])) {
    $t_args = [
      '@title' => !empty($element['#title']) ? $element['#title'] : t('Location'),
    ];
    $form_state
      ->setError($element, t('The @title is not valid.', $t_args));
  }
}