diff --git a/recurring_events.module b/recurring_events.module index 1514b61f06892bda7f3365b9d53765f4c63f1283..0d35b54d6d4d0213eb2da8173011188ef65fa369 100644 --- a/recurring_events.module +++ b/recurring_events.module @@ -158,20 +158,17 @@ function recurring_events_eventseries_insert(EntityInterface $entity) { if (\Drupal::isConfigSyncing()) { return; } + /** @var \Drupal\recurring_events\EventCreationService $creation_service */ $creation_service = \Drupal::service('recurring_events.event_creation_service'); - $creation_service->createInstances($entity); + $instances = $creation_service->createInstances($entity); + foreach ($instances as $instance) { + $instance->set('eventseries_id', $entity->id()); + $instance->setNewRevision(FALSE); - $instances = $entity->event_instances->referencedEntities(); - if (!empty($instances)) { - foreach ($instances as $instance) { - $instance->set('eventseries_id', $entity->id()); - $instance->setNewRevision(FALSE); + $creation_service->configureDefaultInheritances($instance, $entity->id()); + $creation_service->updateInstanceStatus($instance, $entity); - $creation_service->configureDefaultInheritances($instance, $entity->id()); - $creation_service->updateInstanceStatus($instance, $entity); - - $instance->save(); - } + $instance->save(); } } diff --git a/src/EventCreationService.php b/src/EventCreationService.php index bb5bed53a715f5ae95c6dc91d626aac0248e03a6..a6a85529d196662f50eb7eafdeb50c8bd5e070af 100644 --- a/src/EventCreationService.php +++ b/src/EventCreationService.php @@ -439,10 +439,15 @@ class EventCreationService { /** * Create the event instances from the form state. * - * @param Drupal\recurring_events\Entity\EventSeries $event + * @param \Drupal\recurring_events\Entity\EventSeries $event * The stored event series entity. + * + * @return \Drupal\recurring_events\Entity\EventInstance[] + * An array of event instances created for the series. + * + * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ - public function createInstances(EventSeries $event) { + public function createInstances(EventSeries $event): array { $form_data = $this->convertEntityConfigToArray($event); $event_instances = []; @@ -494,6 +499,8 @@ class EventCreationService { $this->messenger->addMessage($this->translation->translate('A total of %items event instances were created as part of this event series.', [ '%items' => count($event_instances), ])); + + return $event_instances; } /**