public function UpdateSettingsForm::validateForm in Drupal 10
Same name and namespace in other branches
- 8 core/modules/update/src/UpdateSettingsForm.php \Drupal\update\UpdateSettingsForm::validateForm()
- 9 core/modules/update/src/UpdateSettingsForm.php \Drupal\update\UpdateSettingsForm::validateForm()
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- core/
modules/ update/ src/ UpdateSettingsForm.php, line 119
Class
- UpdateSettingsForm
- Configure update settings for this site.
Namespace
Drupal\updateCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$form_state
->set('notify_emails', []);
if (!$form_state
->isValueEmpty('update_notify_emails')) {
$valid = [];
$invalid = [];
foreach (explode("\n", trim($form_state
->getValue('update_notify_emails'))) as $email) {
$email = trim($email);
if (!empty($email)) {
if ($this->emailValidator
->isValid($email)) {
$valid[] = $email;
}
else {
$invalid[] = $email;
}
}
}
if (empty($invalid)) {
$form_state
->set('notify_emails', $valid);
}
elseif (count($invalid) == 1) {
$form_state
->setErrorByName('update_notify_emails', $this
->t('%email is not a valid email address.', [
'%email' => reset($invalid),
]));
}
else {
$form_state
->setErrorByName('update_notify_emails', $this
->t('%emails are not valid email addresses.', [
'%emails' => implode(', ', $invalid),
]));
}
}
parent::validateForm($form, $form_state);
}