Problem/Motivation

Error occurs when visiting an event instance URL

InvalidArgumentException: The date cannot be created from a format. in Drupal\Component\Datetime\DateTimePlus::createFromFormat() (line 253 of core/lib/Drupal/Component/Datetime/DateTimePlus.php).

Drupal\recurring_events_registration\RegistrationCreationService->registrationOpeningClosingTime() (Line: 541)
Drupal\recurring_events_registration\RegistrationCreationService->registrationIsOpen() (Line: 497)
recurring_events_registration_eventinstance_view(Array, Object, Object, 'full')
call_user_func_array('recurring_events_registration_eventinstance_view', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('eventinstance_view', Array) (Line: 288)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 786)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 377)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 578)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 717)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Possibly related to https://www.drupal.org/project/recurring_events/issues/3228781 as showing same error

Steps to reproduce

Create an event series with registration enabled and set to:

Registration Type = Entire Series Registration
Registration Date = Scheduled Registration

Registration Opens = some date and time
Registration Closes = some date and time

Comments

endless_wander created an issue. See original summary.

chrisla’s picture

Title: "The date cannot be created from a format" error when using Enitre Series Registration plus Scheduled Registration » "The date cannot be created from a format" error when using Entire Series Registration plus Scheduled Registration
owenbush’s picture

Issue tags: +rc eligible

Thanks for the issue, I'll take a look soon.

chrisla’s picture

Issue tags: -rc eligible

RegistrationCreationService->registrationOpeningClosingTime() at line 600 is returning an empty array when used in RegistrationCreationService->registrationIsOpen() line 541

$reg_date_range array (2)
⇄value => null
⇄end_value => null

getRegistrationDateRange() for same event was returning

$value array (1)
⇄⧉0 => array (16)
⇄value => string (19) "2022-01-14T21:01:01"
⇄end_value => string (0) ""
⇄registration => string (1) "1"
⇄registration_type => string (6) "series"
⇄registration_dates => string (9) "scheduled"
⇄capacity => string (2) "10"
⇄guests_per_registrant => string (1) "0"
⇄waitlist => string (1) "1"
⇄instance_schedule_open => string (6) "custom"
⇄instance_schedule_open_amount => string (1) "1"
⇄instance_schedule_open_units => string (5) "month"
⇄instance_schedule_close => string (3) "end"
⇄instance_schedule_close_amount => string (1) "1"
⇄instance_schedule_close_units => string (4) "week"
⇄instance_schedule_close_type => string (6) "before"
⇄unique_email_address => string (1) "0"

so that should be okay because $value['value'] is there

ah, I see... this code in getRegistrationDateRange() is wrong in this case. the $value array (see above) has a 0 key and so the $date_range array is not getting set:

    $value = $this->eventSeries->event_registration->getValue();
    if (!empty($value)) {
      $date_range['value'] = $value['value'];
      $date_range['end_value'] = $value['end_value'];
    }
chrisla’s picture

Issue tags: +rc eligible

erased tag by mistake

chrisla’s picture

this appears to be the only instance of getRegistrationDateRange used in the module

this patch solves the problem of getRegistrationDateRange() returning an empty array and works as long as the Registration Closes field is not empty

should Registration Closes be required when filling out the Scheduled Registration start and end dates and times? if not, we need to add some more checks to account for that value being empty

chrisla’s picture

Status: Active » Needs review

owenbush’s picture

Status: Needs review » Fixed

Thank you for the patch, this has been merged into the latest dev branches.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.