entityManager = $entityManager; } /** * @Route("/", name="index", methods={"GET"}) * @param TubeRepository $tubeRepository * PaginatorInterface $paginator * Request $request */ public function index(TubeRepository $tubeRepository, PaginatorInterface $paginator, Request $request): Response { $els = $paginator->paginate( $tubeRepository->createQueryBuilder('a')->getQuery(), $request->query->getInt('page', 1), 10 ); return $this->render('admin/crud/index.html.twig', [ 'els'=>$els, 'paginator'=>false, 'search'=>false, 'class'=> Tube::class, 'route'=> 'admin_app_tube', 'breadcrumb'=>[ [ 'text'=>'tous les éléments' ] ], 'fields' => [ 'Id' => 'Id', 'Reference' => 'Reference', 'Couleur' => 'ColorName', 'ColorCss' => 'ColorCss', 'Analyse' => 'Analyse', ], 'title' => 'Tous les élements', 'add_button_label'=>'Ajouter un élément' ]); } /** * @Route("/new", name="new", methods={"GET","POST"}) * @param Request $request * @param TubeHandler $tubeHandler * @param Tools $tools * @return Response */ public function new(Request $request, Tools $tools, TubeHandler $tubeHandler): Response { $tube = new Tube(); $form = $this->createForm(TubeType::class, $tube); if ($tubeHandler->new($form, $request)) { return $this->redirectToRoute('admin_app_tube_index'); } return $this->render('admin/crud/_form.html.twig', [ 'form'=>$form->createView(), 'el'=>$tube, 'button_label'=>'Créer', 'route'=>'admin_app_tube', 'title'=>'Ajouter un élément', 'breadcrumb'=>[ [ 'route'=>'admin_app_tube_index', 'text'=>'tous les éléments' ], [ 'text'=>'ajouter un élément' ] ], ]); } /** * @Route("/edit/{id}", name="edit") * @param Request $request * @param Tube $tube * @param Tools $tools * @return Response */ public function edit(Request $request, Tube $tube, Tools $tools): Response { $form = $this->createForm(TubeType::class, $tube); if ($tubeHandler->edit($form, $request)) { return $this->redirectToRoute('admin_app_tube_edit', ['id'=>$tube->getId()]); } return $this->render('admin/crud/_form.html.twig', [ 'el' => $tube, 'route'=> 'admin_app_tube', 'form' => $form->createView(), 'button_label' => 'Mettre à jour', 'title' => 'Edition', 'breadcrumb'=>[ [ 'route'=>'admin_app_tube_index', 'text'=>'tubes' ], [ 'text'=>'édition ' ] ], ]); } /** * @Route("/{id}", name="delete", methods={"DELETE"}) * @param Request $request * @return Response */ public function delete(Request $request,Tube $tube): Response { if ($this->isCsrfTokenValid('delete'.$tube->getId(), $request->request->get('_token'))) { $this->entityManager->remove($tube); $this->entityManager->flush(); } return $this->redirectToRoute('admin_app_tube_index'); } }