[BUGFIX] Prevent exclude field mixup in FormEngine 72/40272/3
authorAlexander Stehlik <alexander.stehlik@gmail.com>
Mon, 15 Jun 2015 20:17:32 +0000 (22:17 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 6 Jul 2015 20:00:56 +0000 (22:00 +0200)
Use a local variable for storing the excluded fields in the
FormEngine to prevent the configuration from being overwritten
by the inline form element renderer.

Resolves: #47359
Releases: master, 6.2
Change-Id: I5a7a2de16d767f854b4d3f89d599deec28266092
Reviewed-on: http://review.typo3.org/40272
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/Configuration/TCA/tx_inlinetest_inline.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/Configuration/TCA/tx_inlinetest_record.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/ext_emconf.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/ext_tables.sql [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Fixtures/inlinetest.xml [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Form/FormEngineInlineTest.php [new file with mode: 0644]

index 2b5e570..0332eb3 100644 (file)
@@ -546,15 +546,6 @@ class FormEngine {
         */
        public $palFieldTemplate = '';
 
-       // INTERNAL, working memory
-       /**
-        * Set to the fields NOT to display, if any
-        *
-        * @todo Define visibility
-        * @var array|NULL
-        */
-       public $excludeElements = NULL;
-
        /**
         * During rendering of forms this will keep track of which palettes
         * has already been rendered (so they are not rendered twice by mistake)
@@ -831,7 +822,7 @@ class FormEngine {
                        $itemList = $GLOBALS['TCA'][$table]['types'][$typeNum]['showitem'];
                        if ($itemList) {
                                $fields = GeneralUtility::trimExplode(',', $itemList, TRUE);
-                               $excludeElements = ($this->excludeElements = $this->getExcludeElements($table, $row, $typeNum));
+                               $excludeElements = $this->getExcludeElements($table, $row, $typeNum);
                                foreach ($fields as $fieldInfo) {
                                        $parts = explode(';', $fieldInfo);
                                        $theField = trim($parts[0]);
@@ -905,7 +896,7 @@ class FormEngine {
                                                $fields = $this->rearrange($fields);
                                        }
                                        // Get excluded fields, added fiels and put it together:
-                                       $excludeElements = ($this->excludeElements = $this->getExcludeElements($table, $row, $typeNum));
+                                       $excludeElements = $this->getExcludeElements($table, $row, $typeNum);
                                        $fields = $this->mergeFieldsWithAddedFields($fields, $this->getFieldsToAdd($table, $row, $typeNum), $table);
                                        // If TCEforms will render a tab menu in the next step, push the name to the tab stack:
                                        if (strstr($itemList, '--div--') !== FALSE && $this->enableTabMenu && $dividers2tabs) {
@@ -3954,9 +3945,7 @@ TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
        public function loadPaletteElements($table, $row, $palette, $itemList = '') {
                $parts = array();
                // Getting excludeElements, if any.
-               if (!is_array($this->excludeElements)) {
-                       $this->excludeElements = $this->getExcludeElements($table, $row, $this->getRTypeNum($table, $row));
-               }
+               $excludeElements = $this->getExcludeElements($table, $row, $this->getRTypeNum($table, $row));
                // Load the palette TCEform elements
                if ($GLOBALS['TCA'][$table] && (is_array($GLOBALS['TCA'][$table]['palettes'][$palette]) || $itemList)) {
                        $itemList = $itemList ? $itemList : $GLOBALS['TCA'][$table]['palettes'][$palette]['showitem'];
@@ -3967,7 +3956,7 @@ TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
                                        $theField = $fieldParts[0];
                                        if ($theField === '--linebreak--') {
                                                $parts[]['NAME'] = '--linebreak--';
-                                       } elseif (!in_array($theField, $this->excludeElements) && $GLOBALS['TCA'][$table]['columns'][$theField]) {
+                                       } elseif (!in_array($theField, $excludeElements) && $GLOBALS['TCA'][$table]['columns'][$theField]) {
                                                $this->palFieldArr[$palette][] = $theField;
                                                $elem = $this->getSingleField($table, $theField, $row, $fieldParts[1], 1, '', $fieldParts[2]);
                                                if (is_array($elem)) {
diff --git a/typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/Configuration/TCA/tx_inlinetest_inline.php b/typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/Configuration/TCA/tx_inlinetest_inline.php
new file mode 100644 (file)
index 0000000..ff26063
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+return array(
+       'ctrl' => array(
+               'label' => 'text',
+               'title' => 'Subtype test record - inline',
+       ),
+       'interface' => array(
+               'showRecordFieldList' => ''
+       ),
+       'columns' => array(
+               'text' => array(
+                       'label' => 'Dummy text',
+                       'config' => array(
+                               'type' => 'input',
+                       )
+               ),
+       ),
+       'types' => array(
+               '0' => array('showitem' => 'text'),
+       ),
+);
\ No newline at end of file
diff --git a/typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/Configuration/TCA/tx_inlinetest_record.php b/typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/Configuration/TCA/tx_inlinetest_record.php
new file mode 100644 (file)
index 0000000..b7b5166
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+return array(
+       'ctrl' => array(
+               'label' => 'text',
+               'title' => 'Subtype test record',
+               'requestUpdate' => 'subtypeswitch'
+       ),
+       'columns' => array(
+               'subtypeswitch' => array(
+                       'label' => 'Subtype switch',
+                       'config' => array(
+                               'type' => 'select',
+                               'items' => array(
+                                       array('All fields visible', 'fieldsvisible'),
+                                       array('Excluded fields', 'fieldsexcluded'),
+                               ),
+                       ),
+               ),
+               'beforeinline' => array(
+                       'label' => 'Before inline',
+                       'config' => array(
+                               'type' => 'input',
+                       )
+               ),
+               'children' => array(
+                       'label' => 'Children',
+                       'config' => array(
+                               'type' => 'inline',
+                               'foreign_table' => 'tx_inlinetest_inline',
+                               'foreign_field' => 'parent_uid',
+                               'appearance' => array(
+                                       'collapseAll' => FALSE,
+                               ),
+                       )
+               ),
+               'afterinline' => array(
+                       'label' => 'After inline',
+                       'config' => array(
+                               'type' => 'input',
+                       )
+               ),
+       ),
+       'types' => array(
+               0 => array(
+                       'showitem' => '--palette--;;testsettings',
+                       'subtype_value_field' => 'subtypeswitch',
+                       'subtypes_excludelist' => array(
+                               'fieldsexcluded' => 'beforeinline,afterinline'
+                       ),
+               ),
+       ),
+       'palettes' => array(
+               'testsettings' => array(
+                       'showitem' => 'subtypeswitch, --linebreak--, beforeinline, --linebreak--, children, --linebreak--, afterinline',
+                       'canNotCollapse' => 1,
+               ),
+       ),
+);
\ No newline at end of file
diff --git a/typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/ext_emconf.php b/typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/ext_emconf.php
new file mode 100644 (file)
index 0000000..8effea2
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+$EM_CONF[$_EXTKEY] = array(
+       'title' => 'subtypes_exclude_list test',
+       'description' => 'Extension for testing the issue with the TCA setting "subtypes_exclude_list described in #47359',
+       'category' => 'example',
+       'version' => '1.0.0',
+       'state' => 'stable',
+       'uploadfolder' => 0,
+       'createDirs' => '',
+       'clearcacheonload' => 0,
+       'author' => 'Alexander Stehlik',
+       'author_email' => 'alexander.stehlik.deleteme@gmail.com',
+       'author_company' => '',
+       'constraints' => array(
+               'depends' => array(
+                       'typo3' => '6.2.1-0.0.0',
+               ),
+               'conflicts' => array(),
+               'suggests' => array(),
+       ),
+);
\ No newline at end of file
diff --git a/typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/ext_tables.sql b/typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest/ext_tables.sql
new file mode 100644 (file)
index 0000000..e46c6af
--- /dev/null
@@ -0,0 +1,28 @@
+
+#
+# Table structure for table 'tx_inlinetest_record'
+#
+CREATE TABLE tx_inlinetest_record (
+       uid int(11) unsigned NOT NULL auto_increment,
+       pid int(11) unsigned DEFAULT '0' NOT NULL,
+       typeswitch varchar(255) DEFAULT '' NOT NULL,
+       subtypeswitch varchar(255) DEFAULT '' NOT NULL,
+       beforeinline varchar(255) DEFAULT '' NOT NULL,
+       children varchar(255) DEFAULT '' NOT NULL,
+       afterinline int(11) unsigned DEFAULT '0' NOT NULL,
+       PRIMARY KEY (uid),
+       KEY parent (pid)
+);
+
+#
+# Table structure for table 'tx_inlinetest_inline'
+#
+CREATE TABLE tx_inlinetest_inline (
+       uid int(11) unsigned NOT NULL auto_increment,
+       pid int(11) unsigned DEFAULT '0' NOT NULL,
+       parent_uid int(11) unsigned DEFAULT '0' NOT NULL,
+       text text,
+       PRIMARY KEY (uid),
+       KEY parent (pid),
+       KEY parent_node (parent_uid)
+);
diff --git a/typo3/sysext/backend/Tests/Functional/Fixtures/inlinetest.xml b/typo3/sysext/backend/Tests/Functional/Fixtures/inlinetest.xml
new file mode 100644 (file)
index 0000000..6dd7815
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<dataset>
+       <tx_inlinetest_record>
+               <uid>1</uid>
+               <pid>1</pid>
+               <subtypeswitch>fieldsexcluded</subtypeswitch>
+               <children>1</children>
+       </tx_inlinetest_record>
+       <tx_inlinetest_inline>
+               <uid>1</uid>
+               <pid>1</pid>
+               <parent_uid>1</parent_uid>
+       </tx_inlinetest_inline>
+</dataset>
\ No newline at end of file
diff --git a/typo3/sysext/backend/Tests/Functional/Form/FormEngineInlineTest.php b/typo3/sysext/backend/Tests/Functional/Form/FormEngineInlineTest.php
new file mode 100644 (file)
index 0000000..4f89ab8
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Functional\Form;
+
+/**
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Tests\FunctionalTestCase;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Test case
+ */
+class FormEngineInlineTest extends FunctionalTestCase {
+
+       protected $testExtensionsToLoad = array(
+               'typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/inlinetest'
+       );
+
+       /**
+        * @var \TYPO3\CMS\Backend\Form\FormEngine|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $subject;
+
+       /**
+        * Sets up this test case.
+        */
+       public function setUp() {
+               parent::setUp();
+               $this->setUpBackendUserFromFixture(1);
+               $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Fixtures/inlinetest.xml');
+               $GLOBALS['LANG'] = GeneralUtility::makeInstance('TYPO3\\CMS\\Lang\\LanguageService');
+               $GLOBALS['LANG']->init('default');
+               $this->subject = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
+               $this->subject->initDefaultBEmode();
+       }
+
+       /**
+        * Make sure that the exclude field configuration is still valid after
+        * the rendering of an inline element.
+        *
+        * @test
+        */
+       public function excludeElementsAreNotOverwrittenByInlineField() {
+               $rows = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'tx_inlinetest_record', 'uid=1');
+               $mainFields = $this->subject->getMainFields('tx_inlinetest_record', $rows[0]);
+               $this->assertNotContains('afterinline', $mainFields);
+       }
+}