Same filename in this branch
- 10 core/lib/Drupal/Core/Render/Element/Email.php
- 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/Email.php
- 10 core/modules/field/src/Plugin/migrate/field/Email.php
Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Render/Element/Email.php
- 9 core/lib/Drupal/Core/Render/Element/Email.php
Namespace
Drupal\Core\Render\Element
File
core/lib/Drupal/Core/Render/Element/Email.php
View source
<?php
namespace Drupal\Core\Render\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Attribute\FormElement;
use Drupal\Core\Render\Element;
class Email extends FormElementBase {
const EMAIL_MAX_LENGTH = 254;
public function getInfo() {
$class = static::class;
return [
'#input' => TRUE,
'#size' => 60,
'#maxlength' => self::EMAIL_MAX_LENGTH,
'#autocomplete_route_name' => FALSE,
'#process' => [
[
$class,
'processAutocomplete',
],
[
$class,
'processAjaxForm',
],
[
$class,
'processPattern',
],
],
'#element_validate' => [
[
$class,
'validateEmail',
],
],
'#pre_render' => [
[
$class,
'preRenderEmail',
],
],
'#theme' => 'input__email',
'#theme_wrappers' => [
'form_element',
],
];
}
public static function validateEmail(&$element, FormStateInterface $form_state, &$complete_form) {
$value = trim($element['#value']);
$form_state
->setValueForElement($element, $value);
if ($value !== '' && !\Drupal::service('email.validator')
->isValid($value)) {
$form_state
->setError($element, t('The email address %mail is not valid. Use the format user@example.com.', [
'%mail' => $value,
]));
}
}
public static function preRenderEmail($element) {
$element['#attributes']['type'] = 'email';
Element::setAttributes($element, [
'id',
'name',
'value',
'size',
'maxlength',
'placeholder',
]);
static::setAttributes($element, [
'form-email',
]);
return $element;
}
}
Classes