getBooking() ?? throw $this->createNotFoundException(); if ($request->isMethod(Request::METHOD_POST)) { if (!$this->isCsrfTokenValid('remove_accommodation_booking_period_'.$period->getId(), $request->request->getString('_token'))) { throw $this->createAccessDeniedException('Invalid CSRF token.'); } $periodId = $period->getId(); try { $violations = $this->bookingService->removePeriod($booking, $period); } catch (ImplausibleBookingPriceException $e) { $this->logger->error('Refused to remove a period over an implausible accommodation booking total', [ 'exception' => $e, 'id' => $booking->getId(), 'periodId' => $periodId, ]); $this->addFlash('error', ImplausibleBookingPriceException::FORM_ERROR_MESSAGE); return $this->htmxRedirect($request, $this->editUrl($booking, $request)); } // Removing only ever lengthens the main period, so this is reached only when the // stay's dates were already inconsistent with the periods. foreach ($violations as $violation) { $this->addFlash('error', (string) $violation->getMessage()); } if (0 === count($violations)) { $this->addFlash('success', 'Der Zeitraum wurde entfernt.'); $this->logger->info('Removed a period of accommodation booking', [ 'id' => $booking->getId(), 'periodId' => $periodId, ]); } return $this->htmxRedirect($request, $this->editUrl($booking, $request)); } return $this->render('admin/accommodation_booking/modal_remove_period.html.twig', [ 'booking' => $booking, 'period' => $period, 'csrf_token_id' => 'remove_accommodation_booking_period_'.$period->getId(), ]); } }