getBooking() ?? throw $this->createNotFoundException(); $dto = AccommodationBookingPeriodDto::fromPeriod($period); $form = $this->createForm(AccommodationBookingPeriodType::class, $dto, [ 'currency' => $booking->getPricingCurrency() ?? $booking->getAccommodation()?->getCurrency() ?? 'EUR', 'hx_post' => $request->getRequestUri(), ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { try { $violations = $this->bookingService->updatePeriod($booking, $period, $dto); foreach ($violations as $violation) { $form->addError(new FormError((string) $violation->getMessage())); } if (0 === count($violations)) { $this->addFlash('success', 'Der Zeitraum wurde aktualisiert.'); $this->logger->info('Updated a period of accommodation booking', [ 'id' => $booking->getId(), 'periodId' => $period->getId(), 'nights' => $dto->nights, ]); return $this->htmxRedirect($request, $this->editUrl($booking, $request)); } } catch (ImplausibleBookingPriceException $e) { $this->logger->error('Refused to update a period over an implausible accommodation booking total', [ 'exception' => $e, 'id' => $booking->getId(), 'periodId' => $period->getId(), ]); $form->addError(new FormError(ImplausibleBookingPriceException::FORM_ERROR_MESSAGE)); } } return $this->render('admin/accommodation_booking/modal_period.html.twig', [ 'booking' => $booking, 'form' => $form, 'title' => 'Zeitraum bearbeiten', ]); } }