Fatal error when translating event series with modified event instances

Created on 21 June 2024, 7 days ago
Updated 22 June 2024, 6 days ago

Problem/Motivation

When an event series is translated we also need to create translations for each event instance. This work fine, except when an event instance belonging to the series has been changed after initial creation. Then a fatal type error occurs:

TypeError: Drupal\recurring_events\EventCreationService::configureDefaultInheritances(): Argument #1 ($instance) must be of type Drupal\recurring_events\Entity\EventInstance, null given, called in /app/drupal/docroot/modules/contrib/recurring_events/src/EventCreationService.php on line 509 in Drupal\recurring_events\EventCreationService->configureDefaultInheritances() (line 598 of modules/contrib/recurring_events/src/EventCreationService.php).

Steps to reproduce

  1. Create an event series for an exhibition that showcases promising young Italian designers. Set it up as a recurring event every Sunday from 15:00 to 18:00 for the next 4 weeks.
  2. After saving the series, edit the first event instance and change the end time to 23:00 since you are offering free drinks and have invited a DJ to celebrate the opening.
  3. Now create an Italian translation of the event series.

Expected result: the Italian translation is created.
Actual result: the error above is thrown.

Proposed resolution

Currently when an event series is translated, we are calling EventCreationService::createInstances() which is intended to be used for populating event instances on a newly created event series. The logic in this method derives the start and end dates for the event instance dates from the data entered in the form, and later on tries to match these up to existing event instances. This will fail when event instances have been modified.

We should instead iterate over the existing event instances that are referenced on the event series. This is simple and reliable.

API changes

The recurring_events_event_instance alter hook no longer fires when an event instance is translated, but the documentation for recurring_events_event_instance() indicates that this was not the intention, but that this is only intended for altering event instances that are generated when a new event series is created.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Recurring Events (Main module)

Created by

πŸ‡§πŸ‡¬Bulgaria pfrenssen Sofia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024