From 35891c282cbfbc8c90452d3baa86edd5c7f63c62 Mon Sep 17 00:00:00 2001 From: endless_wander <git@users.noreply.drupalcode.org> Date: Thu, 19 Jan 2023 17:25:16 -0700 Subject: [PATCH] Issue #3332526 by endless_wander, owenbush: Registration open/close dates can be empty with series registration --- .../FieldWidget/EventRegistrationWidget.php | 29 +++++++++++++++++++ .../src/RegistrationCreationService.php | 27 +++++++++++------ 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/modules/recurring_events_registration/src/Plugin/Field/FieldWidget/EventRegistrationWidget.php b/modules/recurring_events_registration/src/Plugin/Field/FieldWidget/EventRegistrationWidget.php index f94568a3..dd3a8910 100644 --- a/modules/recurring_events_registration/src/Plugin/Field/FieldWidget/EventRegistrationWidget.php +++ b/modules/recurring_events_registration/src/Plugin/Field/FieldWidget/EventRegistrationWidget.php @@ -158,6 +158,9 @@ class EventRegistrationWidget extends DateRangeDefaultWidget { ':input[name="event_registration[0][registration_dates]"]' => ['value' => 'scheduled'], ], ], + '#element_validate' => [ + [static::class, 'validateSeriesRegistration'], + ], ]; $element['series_registration']['value'] = $element['value']; @@ -417,6 +420,32 @@ class EventRegistrationWidget extends DateRangeDefaultWidget { return $values; } + /** + * Custom validation. + */ + public static function validateSeriesRegistration($element, FormStateInterface $form_state, array $form) { + // check if Series Registration and Scheduled Registration dates are set + $registration = $form_state->getValue('event_registration'); + + if ( + $registration[0]['registration'] == TRUE + && $registration[0]['registration_type'] == 'series' + && $registration[0]['registration_dates'] == 'scheduled' + ) { + if (empty($registration[0]['series_registration']['value']) || empty($registration[0]['series_registration']['end_value'])) { + $error = t('If Scheduled Registration is chosen, registration dates must be set.'); + + if (empty($registration[0]['series_registration']['value'])) { + $form_state->setError($element['value'], $error); + } + + if (empty($registration[0]['series_registration']['end_value'])) { + $form_state->setError($element['end_value'], $error); + } + } + } + } + /** * Validate callback to ensure that the start date <= the end date. * diff --git a/modules/recurring_events_registration/src/RegistrationCreationService.php b/modules/recurring_events_registration/src/RegistrationCreationService.php index 32407476..b893963e 100644 --- a/modules/recurring_events_registration/src/RegistrationCreationService.php +++ b/modules/recurring_events_registration/src/RegistrationCreationService.php @@ -555,18 +555,24 @@ class RegistrationCreationService { */ public function registrationIsOpen() { $registration = FALSE; - if ($this->hasRegistration()) { - $now = new DrupalDateTime(); - $reg_open_close_dates = $this->registrationOpeningClosingTime(); + if (!$this->hasRegistration()) { + return $registration; + } - if (!empty($reg_open_close_dates)) { - $registration = ( - $now->getTimestamp() >= $reg_open_close_dates['reg_open']->getTimestamp() - && $now->getTimestamp() < $reg_open_close_dates['reg_close']->getTimestamp() - ); - } + $now = new DrupalDateTime(); + + $reg_open_close_dates = $this->registrationOpeningClosingTime(); + + if (empty($reg_open_close_dates) || empty($reg_open_close_dates['reg_open']) || empty($reg_open_close_dates['reg_close'])) { + return $registration; } + + $registration = ( + $now->getTimestamp() >= $reg_open_close_dates['reg_open']->getTimestamp() + && $now->getTimestamp() < $reg_open_close_dates['reg_close']->getTimestamp() + ); + return $registration; } @@ -617,6 +623,9 @@ class RegistrationCreationService { // The two registration types are 'series' or 'instance'. switch ($reg_type) { case 'series': + $reg_start = NULL; + $reg_end = NULL; + $reg_date_range = $this->getRegistrationDateRange(); if (!empty($reg_date_range)) { -- GitLab