[BUGFIX] Suggest wizard doesn't work in page flexforms 21/31421/2
authorBernhard Kraft <kraft@webconsulting.at>
Wed, 18 Jun 2014 08:04:28 +0000 (10:04 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Sun, 6 Jul 2014 21:22:16 +0000 (23:22 +0200)
When using the suggest wizard from within a flexform in a page it
doesn't work properly. The $row variable was only set when processing
tables other than pages but is required for proper flexform handling.

Change-Id: I0eec29b3c7266bae809e2753cdee726a4c50b1ab
Resolves: #59642
Releases: 6.3, 6.2, 6.1
Reviewed-on: https://review.typo3.org/31421
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/backend/Classes/Form/Element/SuggestElement.php

index c10089a..793d30a 100644 (file)
@@ -25,9 +25,14 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  */
 class SuggestElement {
 
-       // Count the number of ajax selectors used
+       /**
+        * @var int Count the number of ajax selectors used
+        */
        public $suggestCount = 0;
 
+       /**
+        * @var string
+        */
        public $cssClass = 'typo3-TCEforms-suggest';
 
        /**
@@ -41,8 +46,8 @@ class SuggestElement {
         * @param \TYPO3\CMS\Backend\Form\FormEngine $tceForms Reference to an TCEforms instance
         * @return void
         */
-       public function init(&$tceForms) {
-               $this->TCEformsObj = &$tceForms;
+       public function init($tceForms) {
+               $this->TCEformsObj = $tceForms;
        }
 
        /**
@@ -75,6 +80,7 @@ class SuggestElement {
 
                </div>';
                // Get minimumCharacters from TCA
+               $minChars = 0;
                if (isset($config['fieldConf']['config']['wizards']['suggest']['default']['minimumCharacters'])) {
                        $minChars = (int)$config['fieldConf']['config']['wizards']['suggest']['default']['minimumCharacters'];
                }
@@ -143,11 +149,12 @@ class SuggestElement {
                // If the $uid is numeric, we have an already existing element, so get the
                // TSconfig of the page itself or the element container (for non-page elements)
                // otherwise it's a new element, so use given id of parent page (i.e., don't modify it here)
+               $row = NULL;
                if (is_numeric($uid)) {
+                       $row = BackendUtility::getRecord($table, $uid);
                        if ($table == 'pages') {
                                $pageId = $uid;
                        } else {
-                               $row = BackendUtility::getRecord($table, $uid);
                                $pageId = $row['pid'];
                        }
                }
@@ -156,27 +163,25 @@ class SuggestElement {
                $foreign_table_where = '';
                $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
                $parts = explode('|', $field);
-               if ($GLOBALS['TCA'][$table]['columns'][$parts[0]]['config']['type'] === 'flex') {
-                       if (is_array($row) && count($row) > 0) {
-                               $flexfieldTCAConfig = $GLOBALS['TCA'][$table]['columns'][$parts[0]]['config'];
-                               $flexformDSArray = BackendUtility::getFlexFormDS($flexfieldTCAConfig, $row, $table, $parts[0]);
-                               $flexformDSArray = GeneralUtility::resolveAllSheetsInDS($flexformDSArray);
-                               $flexformElement = $parts[count($parts) - 2];
-                               $continue = TRUE;
-                               foreach ($flexformDSArray as $sheet) {
-                                       foreach ($sheet as $_ => $dataStructure) {
-                                               $fieldConfig = $this->getNestedDsFieldConfig($dataStructure, $flexformElement);
-                                               if (count($fieldConfig) > 0) {
-                                                       $continue = FALSE;
-                                                       break;
-                                               }
-                                       }
-                                       if (!$continue) {
+               if (!empty($row) && $GLOBALS['TCA'][$table]['columns'][$parts[0]]['config']['type'] === 'flex') {
+                       $flexfieldTCAConfig = $GLOBALS['TCA'][$table]['columns'][$parts[0]]['config'];
+                       $flexformDSArray = BackendUtility::getFlexFormDS($flexfieldTCAConfig, $row, $table, $parts[0]);
+                       $flexformDSArray = GeneralUtility::resolveAllSheetsInDS($flexformDSArray);
+                       $flexformElement = $parts[count($parts) - 2];
+                       $continue = TRUE;
+                       foreach ($flexformDSArray as $sheet) {
+                               foreach ($sheet as $dataStructure) {
+                                       $fieldConfig = $this->getNestedDsFieldConfig($dataStructure, $flexformElement);
+                                       if (count($fieldConfig) > 0) {
+                                               $continue = FALSE;
                                                break;
                                        }
                                }
-                               $field = str_replace('|', '][', $field);
+                               if (!$continue) {
+                                       break;
+                               }
                        }
+                       $field = str_replace('|', '][', $field);
                }
                $wizardConfig = $fieldConfig['wizards']['suggest'];
                if (isset($fieldConfig['allowed'])) {
@@ -194,7 +199,7 @@ class SuggestElement {
                                }
                                unset($tableName, $tableConfig);
                        } else {
-                               $queryTables = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $fieldConfig['allowed']);
+                               $queryTables = GeneralUtility::trimExplode(',', $fieldConfig['allowed']);
                        }
                } elseif (isset($fieldConfig['foreign_table'])) {
                        $queryTables = array($fieldConfig['foreign_table']);
@@ -210,7 +215,7 @@ class SuggestElement {
                        if (!is_array($GLOBALS['TCA'][$queryTable]) || !count($GLOBALS['TCA'][$queryTable])) {
                                continue;
                        }
-                       $config = (array) $wizardConfig['default'];
+                       $config = (array)$wizardConfig['default'];
                        if (is_array($wizardConfig[$queryTable])) {
                                \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($config, $wizardConfig[$queryTable]);
                        }