Просмотр исходного кода

Ajout de la suppression des tags orphelins après suppression d'un article

Sangfroid 3 недель назад
Родитель
Сommit
7b50a2cf19
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      src/Controller/ArticleController.php

+ 9 - 2
src/Controller/ArticleController.php

@@ -108,7 +108,7 @@ final class ArticleController extends AbstractController
             if ($publicationChoice !== null) {
                 $workflow->apply($article, $publicationChoice);
             }
-            
+
             $entityManager->flush();
             
             $tagService->clearOrphansTags();
@@ -124,11 +124,18 @@ final class ArticleController extends AbstractController
 
     #[Route('/{id}', name: 'app_article_delete', methods: ['POST'])]
     #[IsGranted('edit', 'article')]
-    public function delete(Request $request, Article $article, EntityManagerInterface $entityManager): Response
+    public function delete(
+        Request $request,
+        Article $article,
+        EntityManagerInterface $entityManager,
+        TagService $tagService
+
+    ): Response
     {
         if ($this->isCsrfTokenValid('delete'.$article->getId(), $request->getPayload()->getString('_token'))) {
             $entityManager->remove($article);
             $entityManager->flush();
+            $tagService->clearOrphansTags();
         }
 
         return $this->redirectToRoute('app_article_index', [], Response::HTTP_SEE_OTHER);