public function ExtraBodyClassesConfigForm::validateForm in Extra body classes 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/ ExtraBodyClassesConfigForm.php, line 186
Class
- ExtraBodyClassesConfigForm
- Configure where you want to append "extra body classes".
Namespace
Drupal\extra_body_classes\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Validation for single day event.
$extra_body_classes_browser_single_day_event = $form_state
->getValue('extra_body_classes_browser_single_day_event');
if (!preg_match("/^[a-zA-Z0-9-_,]*\$/", $extra_body_classes_browser_single_day_event)) {
$form_state
->setErrorByName('extra_body_classes_browser_single_day_event', $this
->t('Single day event class name you have provided is invalid.'));
}
// Validation for multiple day event.
$extra_body_classes_event = $form_state
->getValue('extra_body_classes_event');
if (!preg_match("/^[a-zA-Z0-9-_,]*\$/", $extra_body_classes_event)) {
$form_state
->setErrorByName('extra_body_classes_event', $this
->t('Event class name you have provided is invalid.'));
}
$extra_body_classes_event_start_date = $form_state
->getValue('extra_body_classes_event_start_date');
$extra_body_classes_event_end_date = $form_state
->getValue('extra_body_classes_event_end_date');
$timestamp_current_date = date("Y-m-d");
$timestamp_start_date = strtotime($extra_body_classes_event_start_date);
$timestamp_end_date = strtotime($extra_body_classes_event_end_date);
$timestamp_current_date = strtotime($timestamp_current_date);
// Event start date must be less than end date.
if ($timestamp_start_date > $timestamp_end_date) {
$form_state
->setErrorByName('timestamp_start_date', $this
->t('Event start date must be less than end date.'));
}
// Validation for custom classes.
$extra_body_classes_custom_classes = $form_state
->getValue('extra_body_classes_custom_classes');
if (!preg_match("/^[a-zA-Z0-9-_,]*\$/", $extra_body_classes_custom_classes)) {
$form_state
->setErrorByName('extra_body_classes_custom_classes', $this
->t('Custom class name you have provided is invalid.'));
}
}