public function EmailConfirmerSettingsForm::validateForm in Email confirmer 8
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
- src/
Form/ EmailConfirmerSettingsForm.php, line 276
Class
- EmailConfirmerSettingsForm
- Email confirmer settings form.
Namespace
Drupal\email_confirmer\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Hash expiration validation.
$hash_expiration = intval($form_state
->getValue('hash_expiration'));
if ($hash_expiration < 1) {
$form_state
->setErrorByName('hash_expiration', $this
->t('The miminum hash expiration time is @min_value.', [
'@min_value' => $this
->t('one hour'),
]));
}
elseif ($hash_expiration > 48) {
$form_state
->setErrorByName('hash_expiration', $this
->t('The maximum hash expiration time is @max_value.', [
'@max_value' => $this
->t('@count days', [
'@count' => 2,
]),
]));
}
// Confirmation max lifetime validation.
$lifetime = intval($form_state
->getValue('confirmation_lifetime'));
if ($lifetime > 52) {
$form_state
->setErrorByName('confirmation_lifetime', $this
->t('The maximum confirmation lifetime is @max_value.', [
'@max_value' => $this
->t('one year'),
]));
}
// Request re-sendings delay validation.
$resendrequest_delay = intval($form_state
->getValue('resendrequest_delay'));
if ($resendrequest_delay < 5) {
$form_state
->setErrorByName('resendrequest_delay', $this
->t('The miminum confirmation request resend delay is @min_value.', [
'@min_value' => $this
->t('@count minutes', [
'@count' => 5,
]),
]));
}
elseif ($resendrequest_delay > 60) {
$form_state
->setErrorByName('resendrequest_delay', $this
->t('The maximum confirmation request resend delay is @max_value.', [
'@max_value' => $this
->t('one hour'),
]));
}
// Exit URLs validation.
foreach ([
'confirm',
'cancel',
'error',
] as $page) {
$path = $form_state
->getValue("confirmationresponse_url_{$page}", '<front>');
if ($path != '<front>' && !$this->pathValidator
->isValid($path)) {
$form_state
->setErrorByName("confirmationresponse_url_{$page}", $this
->t("The path '%path' is either invalid or you do not have access to it.", [
'%path' => $path,
]));
}
}
}