From f6de1df83030051d8a3b6596c98267514657dfc5 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 15 Apr 2024 07:30:53 +0100 Subject: [PATCH] Don't sort events if there's only one event --- .../talks/src/EventSubscriber/UpdateTalkNodeBeforeSave.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/modules/custom/talks/src/EventSubscriber/UpdateTalkNodeBeforeSave.php b/web/modules/custom/talks/src/EventSubscriber/UpdateTalkNodeBeforeSave.php index b83ee71..522d8fe 100644 --- a/web/modules/custom/talks/src/EventSubscriber/UpdateTalkNodeBeforeSave.php +++ b/web/modules/custom/talks/src/EventSubscriber/UpdateTalkNodeBeforeSave.php @@ -41,6 +41,12 @@ final class UpdateTalkNodeBeforeSave implements EventSubscriberInterface { private function reorderEvents(Talk $talk): void { $events = $talk->getEvents(); + + // If there is only one event, there's no need to sort them. + if ($events->count() === 1) { + return; + }; + $eventsByDate = $this->sortEventsByDate($events); // If the original event IDs don't match the sorted event IDs, update the event field to use the sorted ones.