public function EditRepeatingRuleModalForm::validateForm in Booking and Availability Management Tools for Drupal 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
- modules/
bat_event_series/ src/ Form/ EditRepeatingRuleModalForm.php, line 170 - Contains \Drupal\bat_event_series\Form\EditRepeatingRuleModalForm.
Class
Namespace
Drupal\bat_event_series\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$start_date = $values['start_date'];
$end_date = $values['end_date'];
$event_series_type = bat_event_series_type_load($this->event_series
->bundle());
$event_type = $event_series_type
->getEventGranularity();
if ($event_type == 'bat_daily') {
$start_date = new \DateTime($start_date);
$end_date = new \DateTime($end_date);
}
$date_start_date = $start_date
->format('Y-m-d');
$date_end_date = $end_date
->format('Y-m-d');
$dates_valid = TRUE;
if ($event_type == 'bat_hourly') {
// Validate the input dates.
if (!$start_date instanceof DrupalDateTime) {
$form_state
->setErrorByName('start_date', $this
->t('The start date is not valid.'));
$dates_valid = FALSE;
}
if (!$end_date instanceof DrupalDateTime) {
$form_state
->setErrorByName('end_date', $this
->t('The end date is not valid.'));
$dates_valid = FALSE;
}
}
if ($dates_valid) {
if ($end_date <= $start_date) {
$form_state
->setErrorByName('end_date', $this
->t('End date must be after the start date.'));
}
}
}