Don't sort events if there's only one event

This commit is contained in:
Oliver Davies 2024-04-15 07:30:53 +01:00
parent b1145ab613
commit f6de1df830

View file

@ -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.