public UpdateSettingsForm::validateForm(array &$form, FormStateInterface $form_state)
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 105
Class
- UpdateSettingsForm
- Configure update settings for this site.
Namespace
Drupal\update
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | public function validateForm( array & $form , FormStateInterface $form_state ) { $form_state ->set( 'notify_emails' , []); if (! $form_state ->isValueEmpty( 'update_notify_emails' )) { $valid = array (); $invalid = array (); 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.' , array ( '%email' => reset( $invalid )))); } else { $form_state ->setErrorByName( 'update_notify_emails' , $this ->t( '%emails are not valid email addresses.' , array ( '%emails' => implode( ', ' , $invalid )))); } } parent::validateForm( $form , $form_state ); } |
Please login to continue.