From 0b577a34a3794ee48f0b83617373d8a0a726701c Mon Sep 17 00:00:00 2001
From: mohamed <mohamed.oun@imt-atlantique.fr>
Date: Wed, 26 Mar 2025 01:49:37 +0100
Subject: [PATCH] SDB

---
 src/Controller/ItemController.php | 11 ++++++++---
 templates/wishlist/show.html.twig | 10 ++++++++--
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/Controller/ItemController.php b/src/Controller/ItemController.php
index f4322979..560ed7c0 100644
--- a/src/Controller/ItemController.php
+++ b/src/Controller/ItemController.php
@@ -94,11 +94,16 @@ final class ItemController extends AbstractController
     #[Route('/{id}', name: 'app_item_delete', methods: ['POST'])]
     public function delete(Request $request, Item $item, EntityManagerInterface $entityManager): Response
     {
-        if ($this->isCsrfTokenValid('delete'.$item->getId(), $request->getPayload()->getString('_token'))) {
+        $wishlistId = $item->getWishlist()->getId();
+    
+        if ($this->isCsrfTokenValid('delete' . $item->getId(), $request->request->get('_token'))) {
             $entityManager->remove($item);
             $entityManager->flush();
         }
-
-        return $this->redirectToRoute('app_item_index', [], Response::HTTP_SEE_OTHER);
+    
+        return $this->redirectToRoute('app_wishlist_show', [
+            'id' => $wishlistId
+        ]);
     }
+    
 }
\ No newline at end of file
diff --git a/templates/wishlist/show.html.twig b/templates/wishlist/show.html.twig
index c9778714..8061f694 100644
--- a/templates/wishlist/show.html.twig
+++ b/templates/wishlist/show.html.twig
@@ -185,7 +185,10 @@
                             <button class="action-btn" onclick="window.open('{{ item.url }}', '_blank')">🛒</button>
                         {% endif %}
                         <button class="action-btn" onclick="window.location.href='{{ path('app_item_edit', {'id': item.id}) }}'">✏️</button>
-                        <button class="action-btn delete-btn" data-delete-url="{{ path('app_item_delete', {'id': item.id}) }}">🗑️</button>
+                        <form method="post" action="{{ path('app_item_delete', {'id': item.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');" style="display:inline;">
+                            <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ item.id) }}">
+                            <button class="action-btn" title="Delete">🗑️</button>
+                        </form>
                     </div>
                 </div>
             </li>
@@ -208,7 +211,10 @@
                             <button class="action-btn" onclick="window.open('{{ item.url }}', '_blank')">🛒</button>
                         {% endif %}
                         <button class="action-btn" onclick="window.location.href='{{ path('app_item_edit', {'id': item.id}) }}'">✏️</button>
-                        <button class="action-btn delete-btn" data-delete-url="{{ path('app_item_delete', {'id': item.id}) }}">🗑️</button>
+                        <form method="post" action="{{ path('app_item_delete', {'id': item.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');" style="display:inline;">
+                            <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ item.id) }}">
+                            <button class="action-btn" title="Delete">🗑️</button>
+                        </form>
                     </div>
                 </div>
             </li>
-- 
GitLab