Prechádzať zdrojové kódy

add distinction whether called by a controller or a form

ksieren 2 rokov pred
rodič
commit
eeb2e4cfdb
1 zmenil súbory, kde vykonal 11 pridanie a 1 odobranie
  1. 11 1
      Classes/Controller/DashboardController.php

+ 11 - 1
Classes/Controller/DashboardController.php

@@ -9,6 +9,7 @@ use Meramo\Begriffmgt\Domain\Repository\UrlRepository;
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
 use Meramo\Begriffmgt\Domain\Repository\TermRepository;
 use Meramo\Begriffmgt\Domain\Repository\CategoryRepository;
+use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
 
 class DashboardController extends ActionController
 {
@@ -72,7 +73,16 @@ class DashboardController extends ActionController
         $url = $this->urlController->createAction($urlTitle);
         $urlObj = $this->urlRepository->findByUid($url);
         $this->termController->createAction($terms, $categoryObj, $typeObj, $urlObj);
-        $this->redirect('index');
+
+        $request = $this->request;
+        if ($request) {
+            // Called by a form action - in this case the data is persisted to the db 'automatically'
+            $this->redirect('index');
+        } else {
+            // Called by another controller
+            $persistenceManager = $this->objectManager->get(PersistenceManager::class);
+            $persistenceManager->persistAll();
+        }
     }
 
     public function deleteTermAction(int $termId): void {