Преглед изворни кода

add dataHandler to trigger event when tt_content gets updated with new chatbot terms stuff

ksieren пре 2 година
родитељ
комит
639e042e76
2 измењених фајлова са 41 додато и 0 уклоњено
  1. 36 0
      Classes/Hooks/TermsDataHandler.php
  2. 5 0
      ext_localconf.php

+ 36 - 0
Classes/Hooks/TermsDataHandler.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace Meramo\Speedbase\Hooks;
+
+use Meramo\Speedbase\Controller\SimpleController;
+use TYPO3\CMS\Core\DataHandling\DataHandler;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+class TermsDataHandler
+{
+
+    public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, DataHandler $dataHandler)
+    {
+        if ($table === 'tt_content') {
+            // Get the CType for the content element
+            $cType = $dataHandler->datamap[$table][$id]['CType'] ?? null;
+
+            if ($cType === 'speedbase') {
+                // $fieldArray contains the updated field values of the content element
+                if ($fieldArray['tx_speedbase_chatbotterms']){
+                    // list of terms in input field got changed
+                    $termsList = $fieldArray['tx_speedbase_chatbotterms'];
+                } else {
+                    // list of terms in input field got not changed just saved
+                    $termsList = $dataHandler->recordInfo($table, $id, 'tx_speedbase_chatbotterms');
+                }
+                $category = $dataHandler->recordInfo($table, $id, 'tx_speedbase_chatbottermscategory');
+                $type = $dataHandler->recordInfo($table, $id, 'tx_speedbase_chatbottermstype');
+                $url = $dataHandler->recordInfo($table, $id, 'tx_speedbase_chatbottermsurl');
+
+                $controller = GeneralUtility::makeInstance(SimpleController::class);
+                $controller->persistDataToDBAction($termsList['tx_speedbase_chatbotterms'], $category['tx_speedbase_chatbottermscategory'], $type['tx_speedbase_chatbottermstype'], $url['tx_speedbase_chatbottermsurl']);
+            }
+        }
+    }
+}

+ 5 - 0
ext_localconf.php

@@ -1,5 +1,6 @@
 <?php
 
+use Meramo\Speedbase\Hooks\TermsDataHandler;
 use TYPO3\CMS\Core\Information\Typo3Version;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -11,3 +12,7 @@ ExtensionManagementUtility::addPageTSConfig('
 @import "EXT:speedbase/Configuration/page.tsconfig"
 ');
 }
+defined('TYPO3_MODE') || die();
+
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['speedbase'] =
+    TermsDataHandler::class;