paginate($page); return $this->render('blog/category_admin/index.html.twig', [ 'pager' => $pager, ]); } /** * @Route("/new", name="admin_blog_category_new") */ public function new(EntityFactory $factory, EntityManager $entityManager, Request $request): Response { $entity = $factory->create(); $form = $this->createForm(EntityType::class, $entity); if ($request->isMethod('POST')) { $form->handleRequest($request); if ($form->isValid()) { $entityManager->create($entity)->flush()->clear(); $this->addFlash('success', 'Donnée enregistrée.'); return $this->redirectToRoute('admin_blog_category_edit', [ 'entity' => $entity->getId(), ]); } $this->addFlash('warning', 'Le formulaire est invalide.'); } return $this->render('blog/category_admin/new.html.twig', [ 'form' => $form->createView(), ]); } /** * @Route("/edit/{entity}", name="admin_blog_category_edit") */ public function edit(Entity $entity, EntityManager $entityManager, Request $request): Response { $form = $this->createForm(EntityType::class, $entity); if ($request->isMethod('POST')) { $form->handleRequest($request); if ($form->isValid()) { $entityManager->update($entity)->flush()->clear(); $this->addFlash('success', 'Donnée enregistrée.'); return $this->redirectToRoute('admin_blog_category_edit', [ 'entity' => $entity->getId(), ]); } $this->addFlash('warning', 'Le formulaire est invalide.'); } return $this->render('blog/category_admin/edit.html.twig', [ 'form' => $form->createView(), 'entity' => $entity, ]); } /** * @Route("/show/{entity}", name="admin_blog_category_show") */ public function show(Entity $entity, PostRepositoryQuery $postQuery): Response { $posts = $postQuery->create() ->orderBy('.publishedAt', 'DESC') ->inCategory($entity) ->paginate(1, 10) ; return $this->render('blog/category_admin/show.html.twig', [ 'entity' => $entity, 'posts' => $posts, ]); } /** * @Route("/delete/{entity}", name="admin_blog_category_delete", methods={"DELETE"}) */ public function delete(Entity $entity, EntityManager $entityManager, Request $request): Response { if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) { $entityManager->delete($entity)->flush()->clear(); $this->addFlash('success', 'Données supprimées.'); } return $this->redirectToRoute('admin_blog_category_index'); } public function getSection(): string { return 'blog_category'; } }