Parcourir la source

add delete action for terms

ksieren il y a 2 ans
Parent
commit
c92b758b6e

+ 6 - 0
Classes/Controller/DashboardController.php

@@ -74,4 +74,10 @@ class DashboardController extends ActionController
         $this->termController->createAction($terms, $categoryObj, $typeObj, $urlObj);
         $this->redirect('index');
     }
+
+    public function deleteTermAction(int $termId): void {
+        $this->termController->deleteAction($termId);
+        $this->redirect('index');
+    }
+
 }

+ 7 - 0
Classes/Controller/TermController.php

@@ -23,4 +23,11 @@ class TermController extends ActionController
             $this->termRepository->add($termObj);
         }
     }
+
+    public function deleteAction(int $termId): void {
+        $term = $this->termRepository->findByUid($termId);
+        if ($term) {
+            $this->termRepository->remove($term);
+        }
+    }
 }

+ 3 - 0
Resources/Private/Templates/Dashboard/Index.html

@@ -44,6 +44,9 @@
         <td>{term.type.title}</td>
         <td>{term.category.title}</td>
         <td>{term.url.title}</td>
+        <td>
+          <f:link.action action="deleteTerm" arguments="{termId: term.uid}" class="btn btn-danger" title="Delete" onclick="return confirm('Are you sure you want to delete this term?');">Delete</f:link.action>
+        </td>
       </tr>
     </f:for>
     </tbody>

+ 1 - 1
ext_tables.php

@@ -12,7 +12,7 @@ call_user_func(function()
     'ChatbotBegriffManagement',
     'top',
     [
-        DashboardController::class => 'index, list, create',
+        DashboardController::class => 'index, list, create, deleteTerm',
     ],
     [
       'access' => 'user,admin',