You are here

public static function GeofieldMapFieldTrait::urlValidate in Geofield Map 8

Form element url format validation handler.

File

src/GeofieldMapFieldTrait.php, line 294

Class

GeofieldMapFieldTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\geofield_map

Code

public static function urlValidate($element, FormStateInterface &$form_state) {
  $path = $element['#value'];

  // Check the jsonValue.
  if (UrlHelper::isExternal($path) && !UrlHelper::isValid($path, TRUE)) {
    $form_state
      ->setError($element, t('The @field field is not valid Url Format.', [
      '@field' => $element['#title'],
    ]));
  }
  elseif (!UrlHelper::isExternal($path)) {
    $path = Url::fromUri('base:' . $path, [
      'absolute' => TRUE,
    ])
      ->toString();
    if (!UrlHelper::isValid($path)) {
      $form_state
        ->setError($element, t('The @field field is not valid internal Drupal path.', [
        '@field' => $element['#title'],
      ]));
    }
  }
}