public function AdvbanSettingsForm::validateForm in Advanced ban 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/ AdvbanSettingsForm.php, line 126
Class
- AdvbanSettingsForm
- Configure advban settings for this site.
Namespace
Drupal\advban\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Expiry durations validate.
$arr_advban_expiry_durations = explode("\n", $form_state
->getValue('advban_expiry_durations'));
// Check for wrong time formats.
foreach ($arr_advban_expiry_durations as $key => $duration) {
if (!strtotime($duration)) {
$form_state
->setErrorByName('advban_expiry_durations', $this
->t('Expiry time formats has wrong expiry time %duration.', [
'%duration' => $duration,
]));
}
$arr_advban_expiry_durations[$key] = trim($arr_advban_expiry_durations[$key]);
}
// Check for expiry durations doubles.
if (count($arr_advban_expiry_durations) != count(array_flip($arr_advban_expiry_durations))) {
$form_state
->setErrorByName('advban_expiry_durations', $this
->t('Expiry durations has dublicated items'));
}
}