Commit bdb618db authored by alexpott's avatar alexpott

Issue #2417327 by cilefen: Remove usages of the deprecated valid_email_address()

parent 262a3e76
......@@ -64,7 +64,7 @@ public static function validateEmail(&$element, FormStateInterface $form_state,
$value = trim($element['#value']);
$form_state->setValueForElement($element, $value);
if ($value !== '' && !valid_email_address($value)) {
if ($value !== '' && !\Drupal::service('email.validator')->isValid($value)) {
$form_state->setError($element, t('The email address %mail is not valid.', array('%mail' => $value)));
}
}
......
......@@ -17,6 +17,7 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Utility\Token;
use Psr\Log\LoggerInterface;
use Egulias\EmailValidator\EmailValidator;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -64,6 +65,13 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug
*/
protected $languageManager;
/**
* The email validator.
*
* @var \Egulias\EmailValidator\EmailValidator
*/
protected $emailValidator;
/**
* Constructs a EmailAction object.
*
......@@ -83,8 +91,10 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug
* The mail manager.
* @param \Drupal\Core\Language\LanguageManagerInterface
* The language manager.
* @param \Egulias\EmailValidator\EmailValidator $email_validator
* The email validator.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, EntityManagerInterface $entity_manager, LoggerInterface $logger, MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, EntityManagerInterface $entity_manager, LoggerInterface $logger, MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager, EmailValidator $email_validator) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->token = $token;
......@@ -92,6 +102,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$this->logger = $logger;
$this->mailManager = $mail_manager;
$this->languageManager = $language_manager;
$this->emailValidator = $email_validator;
}
/**
......@@ -103,7 +114,8 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('entity.manager'),
$container->get('logger.factory')->get('action'),
$container->get('plugin.manager.mail'),
$container->get('language_manager')
$container->get('language_manager'),
$container->get('email.validator')
);
}
......@@ -182,7 +194,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
if (!valid_email_address($form_state->getValue('recipient')) && strpos($form_state->getValue('recipient'), ':mail') === FALSE) {
if (!$this->emailValidator->isValid($form_state->getValue('recipient')) && strpos($form_state->getValue('recipient'), ':mail') === FALSE) {
// We want the literal %author placeholder to be emphasized in the error message.
$form_state->setErrorByName('recipient', t('Enter a valid email address or use a token email address such as %author.', array('%author' => '[node:author:mail]')));
}
......
......@@ -8,18 +8,46 @@
namespace Drupal\contact;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\ConfigFormBaseTrait;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Egulias\EmailValidator\EmailValidator;
/**
* Base form for contact form edit forms.
*/
class ContactFormEditForm extends EntityForm {
class ContactFormEditForm extends EntityForm implements ContainerInjectionInterface {
use ConfigFormBaseTrait;
/**
* The email validator.
*
* @var \Egulias\EmailValidator\EmailValidator
*/
protected $emailValidator;
/**
* Constructs a new ContactFormEditForm.
*
* @param \Egulias\EmailValidator\EmailValidator $email_validator
* The email validator.
*/
public function __construct(EmailValidator $email_validator) {
$this->emailValidator = $email_validator;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('email.validator')
);
}
/**
* {@inheritdoc}
*/
......@@ -92,7 +120,7 @@ public function validate(array $form, FormStateInterface $form_state) {
foreach ($recipients as &$recipient) {
$recipient = trim($recipient);
if (!valid_email_address($recipient)) {
if (!$this->emailValidator->isValid($recipient)) {
$form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
}
}
......
......@@ -7,13 +7,42 @@
namespace Drupal\update;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Egulias\EmailValidator\EmailValidator;
/**
* Configure update settings for this site.
*/
class UpdateSettingsForm extends ConfigFormBase {
class UpdateSettingsForm extends ConfigFormBase implements ContainerInjectionInterface {
/**
* The email validator.
*
* @var \Egulias\EmailValidator\EmailValidator
*/
protected $emailValidator;
/**
* Constructs a new UpdateSettingsForm.
*
* @param \Egulias\EmailValidator\EmailValidator $email_validator
* The email validator.
*/
public function __construct(EmailValidator $email_validator) {
$this->emailValidator = $email_validator;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('email.validator')
);
}
/**
* {@inheritdoc}
......@@ -86,7 +115,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
$email = trim($email);
if (!empty($email)) {
if (valid_email_address($email)) {
if ($this->emailValidator->isValid($email)) {
$valid[] = $email;
}
else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment