[BUGFIX] Undefined switchable controller actions must be removed 30/22030/5
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Sat, 6 Jul 2013 15:39:05 +0000 (17:39 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 17 Jul 2013 11:36:20 +0000 (13:36 +0200)
Currently there is no check if switchable controller actions in
pi_flexform are still present in the configuration flexform. So,
when removing the flexforms in the configuration file, the
switchable controller actions section is not deleted in pi_flexform.

This change removes all occurences in the present pi_flexform, so
if no switchable controller actions are defined any longer, they
will be removed, else they are overwritten by the current flexform
data.

Releases: 6.2
Resolves: #31198
Change-Id: I6046b29dbf436d8c970593dbc6fd2c216f222c52
Reviewed-on: https://review.typo3.org/22030
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Hook/DataHandler/CheckFlexFormValue.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Hook/DataHandler/CheckFlexFormValueTest.php [new file with mode: 0644]
typo3/sysext/extbase/ext_tables.php

diff --git a/typo3/sysext/extbase/Classes/Hook/DataHandler/CheckFlexFormValue.php b/typo3/sysext/extbase/Classes/Hook/DataHandler/CheckFlexFormValue.php
new file mode 100644 (file)
index 0000000..9f65f3d
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+namespace TYPO3\CMS\Extbase\Hook\DataHandler;
+
+/*                                                                        *
+ * This script belongs to the Extbase framework                           *
+ *                                                                        *
+ * It is free software; you can redistribute it and/or modify it under    *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License, or (at your *
+ * option) any later version.                                             *
+ *                                                                        *
+ * This script is distributed in the hope that it will be useful, but     *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
+ * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
+ * General Public License for more details.                               *
+ *                                                                        *
+ * You should have received a copy of the GNU Lesser General Public       *
+ * License along with the script.                                         *
+ * If not, see http://www.gnu.org/licenses/lgpl.html                      *
+ *                                                                        *
+ * The TYPO3 project - inspiring people to share!                         *
+ *                                                                        */
+
+use \TYPO3\CMS\Core\DataHandling\DataHandler;
+
+/**
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ * @api
+ */
+class CheckFlexFormValue {
+
+       /**
+        * Check flexform value before merge
+        *
+        * @param DataHandler $dataHander
+        * @param array &$currentValue
+        * @param array &$newValue
+        * @return void
+        */
+       public function checkFlexFormValue_beforeMerge(DataHandler $dataHander, array &$currentValue, array &$newValue) {
+               $currentValue = $this->removeSwitchableControllerActionsRecursive($currentValue);
+       }
+
+       /**
+        * Remove switchable controller actions recursively
+        *
+        * @param array $a
+        * @return array
+        */
+       protected function removeSwitchableControllerActionsRecursive(array $a) {
+               $r = array();
+
+               foreach ($a as $k => $v) {
+                       if ($k === 'switchableControllerActions') {
+                               continue;
+                       }
+
+                       $r[$k] = is_array($v) ? $this->removeSwitchableControllerActionsRecursive($v) : $v;
+               }
+
+               return $r;
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Hook/DataHandler/CheckFlexFormValueTest.php b/typo3/sysext/extbase/Tests/Unit/Hook/DataHandler/CheckFlexFormValueTest.php
new file mode 100644 (file)
index 0000000..939d59e
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Hook\DataHandler;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+class CheckFlexFormValueTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Core\DataHandling\DataHandler
+        */
+       protected $dataHandler;
+
+       public function setUp() {
+               $this->dataHandler = $this->objectManager->get('TYPO3\CMS\Core\DataHandling\DataHandler');
+       }
+
+       /**
+        * @test
+        */
+       public function checkFlexFormValueBeforeMergeRemovesSwitchableControllerActions() {
+               $currentFlexFormDataArray = array(
+                       'foo' => array(
+                               'bar' => 'baz',
+                               'qux' => array(
+                                       'quux' => 'quuux',
+                                       'switchableControllerActions' => array()
+                               ),
+                               'switchableControllerActions' => array()
+                       ),
+                       'switchableControllerActions' => array()
+               );
+
+               $expectedFlexFormDataArray = array(
+                       'foo' => array(
+                               'bar' => 'baz',
+                               'qux' => array(
+                                       'quux' => 'quuux',
+                               ),
+                       ),
+               );
+
+               $newFlexFormDataArray = array();
+               /** @var \TYPO3\CMS\Extbase\Hook\DataHandler\CheckFlexFormValue $checkFlexFormValue */
+               $checkFlexFormValue = $this->objectManager->get('TYPO3\CMS\Extbase\Hook\DataHandler\CheckFlexFormValue');
+               $checkFlexFormValue->checkFlexFormValue_beforeMerge($this->dataHandler, $currentFlexFormDataArray, $newFlexFormDataArray);
+
+               $this->assertSame($expectedFlexFormDataArray, $currentFlexFormDataArray);
+       }
+}
+
+?>
\ No newline at end of file
index 6fcca7f..aff0b26 100644 (file)
@@ -57,4 +57,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['TYPO3\\CMS\\Ext
        'description' => 'LLL:EXT:extbase/Resources/Private/Language/locallang_db.xlf:task.description',
        'additionalFields' => 'TYPO3\\CMS\\Extbase\\Scheduler\\FieldProvider'
 );
-?>
\ No newline at end of file
+
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'][] = 'TYPO3\CMS\Extbase\Hook\DataHandler\CheckFlexFormValue';
+
+?>