Skip to content
Snippets Groups Projects
Commit 35891c28 authored by endless_wander's avatar endless_wander Committed by Owen Bush
Browse files

Issue #3332526 by endless_wander, owenbush: Registration open/close dates can...

Issue #3332526 by endless_wander, owenbush: Registration open/close dates can be empty with series registration
parent 9ac66d14
No related branches found
No related tags found
No related merge requests found
......@@ -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.
*
......
......@@ -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)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment