public function EmaillogConfigForm::validateForm in Logging and alerts 8
Same name and namespace in other branches
- 2.0.x emaillog/src/Form/EmaillogConfigForm.php \Drupal\emaillog\Form\EmaillogConfigForm::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
- emaillog/
src/ Form/ EmaillogConfigForm.php, line 150
Class
- EmaillogConfigForm
- Provides a setting UI for emaillog.
Namespace
Drupal\emaillog\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$userInputValues = $form_state
->getUserInput();
if ($userInputValues['emaillog_max_similar_emails'] && !$userInputValues['emaillog_max_similarity_level']) {
$form_state
->setErrorByName('emaillog_max_similarity_level', $this
->t('You need to provide value for %field1 field when specifying %field2.', [
'%field1' => 'Maximum allowed similarity level between consecutive email alerts',
'%field2' => 'Maximum number of allowed consecutive similar emails',
]));
}
if ($userInputValues['emaillog_max_similarity_level'] && !$userInputValues['emaillog_max_similar_emails']) {
$form_state
->setErrorByName('emaillog_max_similar_emails', $this
->t('You need to provide value for %field1 field when specifying %field2.', [
'%field1' => 'Maximum number of allowed consecutive similar emails',
'%field2' => 'Maximum allowed similarity level between consecutive email alerts',
]));
}
if ($userInputValues['emaillog_max_consecutive_timespan'] && !$userInputValues['emaillog_max_similar_emails']) {
$form_state
->setErrorByName('emaillog_max_similar_emails', $this
->t('You need to provide value for %field1 field when specifying %field2.', [
'%field1' => 'Maximum number of allowed consecutive similar emails',
'%field2' => 'Email alerts should be considered "consecutive" if sent within',
]));
}
if ($userInputValues['emaillog_max_consecutive_timespan'] && !$userInputValues['emaillog_max_similarity_level']) {
$form_state
->setErrorByName('emaillog_max_similarity_level', $this
->t('You need to provide value for %field1 field when specifying %field2.', [
'%field1' => 'Maximum allowed similarity level between consecutive email alerts',
'%field2' => 'Email alerts should be considered "consecutive" if sent within',
]));
}
if ($userInputValues['emaillog_max_similarity_level']) {
if (!is_numeric($userInputValues['emaillog_max_similarity_level'])) {
$form_state
->setErrorByName('emaillog_max_similarity_level', $this
->t('Value of %field cannot contain any non-numeric characters.', [
'%field' => 'Maximum allowed similarity level between consecutive email alerts',
]));
}
if ($userInputValues['emaillog_max_similarity_level'] < 0 || $userInputValues['emaillog_max_similarity_level'] > 1) {
$form_state
->setErrorByName('emaillog_max_similarity_level', $this
->t('Value of %field needs to be in [0-1] range.', [
'%field' => 'Maximum allowed similarity level between consecutive email alerts',
]));
}
}
}