public static function Uri::validateUrl in Feeds 8.3
Form element validation handler for #type 'feeds_uri'.
Overrides Url::validateUrl
1 call to Uri::validateUrl()
- UriTest::testValidation in tests/
src/ Unit/ Element/ UriTest.php - Tests validation.
File
- src/
Element/ Uri.php, line 28
Class
- Uri
- Provides a form element for input of a URI.
Namespace
Drupal\feeds\ElementCode
public static function validateUrl(&$element, FormStateInterface $form_state, &$complete_form, StreamWrapperManagerInterface $stream_wrapper_manager = NULL) {
if (empty($stream_wrapper_manager)) {
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
}
$value = $stream_wrapper_manager
->normalizeUri(trim($element['#value']));
$form_state
->setValueForElement($element, $value);
if (!$value) {
return;
}
$parsed = parse_url($value);
$valid = $parsed && !empty($parsed['scheme']) && !empty($parsed['host']);
if (!$valid) {
$form_state
->setError($element, t('The URI %url is not valid.', [
'%url' => $value,
]));
return;
}
if ($element['#allowed_schemes'] && !in_array(static::getScheme($value), $element['#allowed_schemes'], TRUE)) {
$args = [
'%scheme' => static::getScheme($value),
'@schemes' => implode(', ', $element['#allowed_schemes']),
];
$form_state
->setError($element, t("The scheme %scheme is invalid. Available schemes: @schemes.", $args));
}
}