MyAccountAction::BASE_URL_EN.'/service/{id}/conversation', 'fr' => MyAccountAction::BASE_URL_FR.'/service/{id}/conversation', ], name: self::ROUTE, requirements: ['id' => Requirement::UUID_V6])] public function __invoke(Request $request, string $id): Response { $serviceRequest = $this->getMyServiceRequest($id); $this->commandBus->dispatch(new TryAutoFinalizeCommand($serviceRequest->getId())); $this->commandBus->dispatch(new ReadMessagesCommand($serviceRequest->getId(), $this->getAppUser()->getId())); // we need to refresh the entity in case it was modified by the commands $serviceRequest = $this->getMyServiceRequest($id); // form to add a new message $form = $this->createForm(NewMessageType::class)->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { /** @var Message $message */ $message = $form->getData(); $this->commandBus->dispatch(new CreateMessageCommand($serviceRequest->getId(), $this->getAppUser()->getId(), $message->getMessage())); $this->addFlashSuccess($this->getI18nPrefix().'.flash.success'); return $this->redirectToRoute(self::ROUTE, ['id' => $id]); } // form to modify the dates of the service request $modifyForm = $this->createForm(ModifyServiceRequestType::class, $serviceRequest)->handleRequest($request); return $this->render('pages/account/conversation.html.twig', [ 'service_request' => $serviceRequest, 'form' => $form, 'modify_form' => $modifyForm, ]); } }