Same filename in this branch
- 10 core/lib/Drupal/Core/Url.php
- 10 core/lib/Drupal/Core/Render/Element/Url.php
- 10 core/modules/views/src/Plugin/views/field/Url.php
Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Render/Element/Url.php
- 9 core/lib/Drupal/Core/Render/Element/Url.php
Namespace
Drupal\Core\Render\Element
File
core/lib/Drupal/Core/Render/Element/Url.php
View source
<?php
namespace Drupal\Core\Render\Element;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Attribute\FormElement;
use Drupal\Core\Render\Element;
class Url extends FormElementBase {
public function getInfo() {
$class = static::class;
return [
'#input' => TRUE,
'#size' => 60,
'#maxlength' => 255,
'#autocomplete_route_name' => FALSE,
'#process' => [
[
$class,
'processAutocomplete',
],
[
$class,
'processAjaxForm',
],
[
$class,
'processPattern',
],
],
'#element_validate' => [
[
$class,
'validateUrl',
],
],
'#pre_render' => [
[
$class,
'preRenderUrl',
],
],
'#theme' => 'input__url',
'#theme_wrappers' => [
'form_element',
],
];
}
public static function validateUrl(&$element, FormStateInterface $form_state, &$complete_form) {
$value = trim($element['#value']);
$form_state
->setValueForElement($element, $value);
if ($value !== '' && !UrlHelper::isValid($value, TRUE)) {
$form_state
->setError($element, t('The URL %url is not valid.', [
'%url' => $value,
]));
}
}
public static function preRenderUrl($element) {
$element['#attributes']['type'] = 'url';
Element::setAttributes($element, [
'id',
'name',
'value',
'size',
'maxlength',
'placeholder',
]);
static::setAttributes($element, [
'form-url',
]);
return $element;
}
}
Classes