navList = NavList::LIST; $this->navList['referral_sources'] = NavList::PRESENT_LINK; } #[Route('/list-referral-sources', name: 'app_referral_source')] public function listReferralSources(#[CurrentUser()] User $user): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->msgs = Libs::getMessages($user, $this->entityManager); $sources = $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(); return $this->render( 'internal/admin/referral_source/list-referral-sources.html.twig', array_merge( $this->navList, [ 'sources' => $sources, 'notifications' => $this->msgs, 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_referral_source'), 'Referral Sources') ] ] ) ); } #[Route('/add-source', name: 'app_add_source')] public function addSource(Request $request, #[CurrentUser()] User $user): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->msgs = Libs::getMessages($user, $this->entityManager); $rs = new ReferralSource(); $form = $this->createForm(ReferralSourceFormType::class, $rs); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $rs = $form->getData(); $this->entityManager->persist($rs); $this->entityManager->flush(); $this->addFlash('success', 'Referral Source added'); return $this->redirectToRoute('app_referral_source'); } return $this->render( 'internal/admin/referral_source/add-source.html.twig', array_merge( $this->navList, [ 'form' => $form, 'notifications' => $this->msgs, 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_referral_source'), 'Referral Sources'), new Breadcrumb($this->generateUrl('app_add_source'), 'Add Source') ] ] ) ); } #[Route('/edit-source/{id}', name: 'app_edit_source')] public function editSource(Request $request, #[CurrentUser()] User $user, string $id): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->msgs = Libs::getMessages($user, $this->entityManager); $rs = $this->entityManager->getRepository(ReferralSource::class)->find($id); $form = $this->createForm(ReferralSourceFormType::class, $rs); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $rs = $form->getData(); $this->entityManager->flush(); $this->addFlash('success', 'Referral Source Updated'); return $this->redirectToRoute('app_referral_source'); } return $this->render( 'internal/admin/referral_source/edit-source.html.twig', array_merge( $this->navList, [ 'form' => $form, 'rs' => $rs, 'notifications' => $this->msgs, 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_referral_source'), 'Referral Sources'), new Breadcrumb($this->generateUrl('app_edit_source', ['id' => $id]), 'Edit Source') ] ] ) ); } }