[FEATURE] Add checkFlexFormValue hook in DataHandler 29/21929/3
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Fri, 5 Jul 2013 13:05:58 +0000 (15:05 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 5 Jul 2013 14:37:01 +0000 (16:37 +0200)
Currently there is a problem with updating flexform values
right as there is no check if an existing value in the db
has actually been deleted.

This e.g. is a problem when it comes to saving switchable
controller actions (Extbase) in the flexform. Old actions
that may not be present any longer have to be removed
manually.

As there is currently no overall solution to this issue
there should at least be a hook to adjust the old flexform
data right before it is merged with the new one.

Releases: 6.2
Resolves: #49699
Change-Id: Ic93ffd7782b4d049070c6bd9ab760a01008242d6
Reviewed-on: https://review.typo3.org/21929
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php

index 1dc1548..4c5c1aa 100644 (file)
@@ -2001,6 +2001,16 @@ class DataHandler {
                        // Here we convert the currently submitted values BACK to an array, then merge the two and then BACK to XML again. This is needed to ensure the charsets are the same (provided that the current value was already stored IN the charset that the new value is converted to).
                        if (is_array($currentValueArray)) {
                                $arrValue = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($xmlValue);
+
+                               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'])) {
+                                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'] as $classRef) {
+                                               $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
+                                               if (method_exists($hookObject, 'checkFlexFormValue_beforeMerge')) {
+                                                       $hookObject->checkFlexFormValue_beforeMerge($this, $currentValueArray, $arrValue);
+                                               }
+                                       }
+                               }
+
                                $arrValue = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($currentValueArray, $arrValue);
                                $xmlValue = $this->checkValue_flexArray2Xml($arrValue, TRUE);
                        }
index 1503e76..f618908 100644 (file)
@@ -285,6 +285,18 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $fixture->process_datamap();
        }
 
+       /**
+        * @test
+        */
+       public function doesCheckFlexFormValueHookGetsCalled() {
+               $hookClass = uniqid('tx_coretest');
+               $hookMock = $this->getMock($hookClass, array('checkFlexFormValue_beforeMerge'));
+               $hookMock->expects($this->once())->method('checkFlexFormValue_beforeMerge');
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'][] = $hookClass;
+               $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock;
+               $this->fixture->checkValue_flex(array(), array(), array(), array(), array(), '');
+       }
+
        /////////////////////////////////////
        // Tests concerning log
        /////////////////////////////////////