[FEATURE] Add hooks for DatabaseRecordList CSV actions 48/57648/3
authorGuido Schmechel <guido.schmechel@brandung.de>
Sat, 21 Jul 2018 08:58:54 +0000 (10:58 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Sun, 5 Aug 2018 11:47:19 +0000 (13:47 +0200)
Now it is possible to customize the csv output
in the DatabaseRecordList with a hook.

The following two hooks were implemented:
- customizeCsvHeader for the header
- customizeCsvRow for a single row

Resolves: #85590
Releases: master
Change-Id: Id80f7d22811c012d8f4671ce2e97956afc8a21db
Reviewed-on: https://review.typo3.org/57648
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Łukasz Uznański <l.uznanski@macopedia.pl>
Tested-by: Łukasz Uznański <l.uznanski@macopedia.pl>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Feature-85590-AddHooksForDatabaseRecordListCSVActions.rst [new file with mode: 0644]
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-85590-AddHooksForDatabaseRecordListCSVActions.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-85590-AddHooksForDatabaseRecordListCSVActions.rst
new file mode 100644 (file)
index 0000000..49a49ac
--- /dev/null
@@ -0,0 +1,33 @@
+.. include:: ../../Includes.txt
+
+==============================================================
+Feature: #85590 - Add hooks for DatabaseRecordList CSV actions
+==============================================================
+
+See :issue:`85590`
+
+Description
+===========
+
+Now it is possible to customize the csv output in the DatabaseRecordList with a hook.
+
+The following two hooks were implemented:
+- customizeCsvHeader for the header
+- customizeCsvRow for a single row
+
+
+Impact
+======
+
+Now you can influence the output of the CSV files in the DatabaseRecordList with hooks. For this you can
+register the hooks in an extension.
+
+Example:
+
+.. code-block:: php
+
+$hookName = DatabaseRecordList::class;
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['customizeCsvRow'][] = \Vendor\ExtName\Hooks\CsvTest::class . '->customizeCsvRow';
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['customizeCsvHeader'][] = \Vendor\ExtName\Hooks\CsvTest::class . '->customizeCsvHeader';
+
+.. index:: Backend
\ No newline at end of file
index 9ef9952..2916e1b 100644 (file)
@@ -1508,6 +1508,17 @@ class DatabaseRecordList
         }
         // Add row to CSV list:
         if ($this->csvOutput) {
+            $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][__CLASS__]['customizeCsvRow'] ?? [];
+            if (!empty($hooks)) {
+                $hookParameters = [
+                    'databaseRow' => &$row,
+                    'tableName' => $table,
+                    'pageId' => $this->id
+                ];
+                foreach ($hooks as $hookFunction) {
+                    GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
+                }
+            }
             $this->addToCSV($row);
         }
         // Add classes to table cells
@@ -2698,8 +2709,18 @@ class DatabaseRecordList
      */
     protected function addHeaderRowToCSV()
     {
+        $fieldArray = array_combine($this->fieldArray, $this->fieldArray);
+        $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][__CLASS__]['customizeCsvHeader'] ?? [];
+        if (!empty($hooks)) {
+            $hookParameters = [
+                'fields' => &$fieldArray
+            ];
+            foreach ($hooks as $hookFunction) {
+                GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
+            }
+        }
         // Add header row, control fields will be reduced inside addToCSV()
-        $this->addToCSV(array_combine($this->fieldArray, $this->fieldArray));
+        $this->addToCSV($fieldArray);
     }
 
     /**