loadSource($request, $id); $view = $this->view($source, 200) ->setTemplate((new SourceTemplateFactory($source, $request))->getTemplatePath()) ->setTemplateVar('source'); return $this->handleView($view); } /** * * @Route("/source/{id}.{_format}/edit", defaults={"_format"="html"}) */ public function edit(Request $request, int $id): Response { $source = $this->loadSource($request, $id); $form = $this->createForm((new SourceFormFactory($source))->getNamespace(), $source); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $source = $form->getData(); $this->saveSource($source); } return $this->render((new SourceTemplateFormFactory($source, $request))->getTemplatePath(), array( 'form' => $form->createView(), )); } private function loadSource(Request $request, int $id): SourceInterface { $source = $this->getDoctrine() ->getRepository(AbstractSource::class) ->find($id); if (! $source) { throw $this->createNotFoundException('No source found for id ' . $id); } return $source; } private function saveSource(SourceInterface $source): void { $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($source); $entityManager->flush(); } }