getUser(); if ($user instanceof User) { $booking->setManagedBy($user); } $form = $this->createForm(AccommodationBookingCreateType::class, $booking, [ 'hx_post' => $request->getRequestUri(), ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid() && $this->refreshPriceSnapshot($form, $booking)) { $this->entityManager->persist($booking); $this->entityManager->flush(); $this->addFlash('success', 'Die Buchung wurde erstellt'); $this->logger->info('Created accommodation booking', [ 'id' => $booking->getId(), ]); return new HxRedirectResponse( $this->generateUrl('app_admin_accommodationbooking_edit', ['id' => $booking->getId()]) ); } return $this->render('admin/accommodation_booking/modal_create.html.twig', [ 'form' => $form, ]); } /** * The price is computed after validation, so an implausible total cannot be a constraint on * the form — it is reported as one anyway, because the office's next move is to go and fix * the house's prices, not to read an error page. * * @param FormInterface $form */ private function refreshPriceSnapshot(FormInterface $form, AccommodationBooking $booking): bool { try { $this->bookingService->refreshPriceSnapshot($booking); return true; } catch (ImplausibleBookingPriceException $e) { $this->logger->error('Refused to store an implausible accommodation booking total', [ 'exception' => $e, 'id' => $booking->getId(), 'accommodation' => $booking->getAccommodation()?->getCalendarCode(), 'paxCount' => $booking->getPaxCount(), 'nights' => $booking->getNights(), ]); $form->addError(new FormError(ImplausibleBookingPriceException::FORM_ERROR_MESSAGE)); return false; } } }