[BUGFIX] Suggest wizard broken when used in a repeating flexform element 90/20990/7
authorGabe Blair <gabe@castironcoding.com>
Thu, 23 May 2013 00:03:10 +0000 (17:03 -0700)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 6 Sep 2013 17:37:39 +0000 (19:37 +0200)
Get correct fieldConfig when in repeating flexform. Adjust
JavaScript a bit to make this work.

Resolves: #48474
Releases: 6.2, 6.1, 6.0
Change-Id: I7c8a5ecfc2f1d7cfb10ca86a40a3429d3a60ee1f
Reviewed-on: https://review.typo3.org/20990
Reviewed-by: Zach Davis
Tested-by: Zach Davis
Reviewed-by: Mattias Nilsson
Tested-by: Mattias Nilsson
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/backend/Classes/Form/Element/SuggestElement.php
typo3/sysext/backend/Resources/Public/JavaScript/jsfunc.tceforms_suggest.js

index d2f8a56..7339670 100644 (file)
@@ -106,6 +106,33 @@ class SuggestElement {
        }
 
        /**
+        * Search a data structure array recursively -- including within nested
+        * (repeating) elements -- for a particular field config.
+        *
+        * @param array $dataStructure The data structure
+        * @param string $fieldName The field name
+        * @return array
+        */
+       protected function getNestedDsFieldConfig(array $dataStructure, $fieldName) {
+               $fieldConfig = array();
+               $elements = $dataStructure['ROOT']['el'] ? $dataStructure['ROOT']['el'] : $dataStructure['el'];
+               if (is_array($elements)) {
+                       foreach ($elements as $k => $ds) {
+                               if ($k === $fieldName) {
+                                       $fieldConfig = $ds['TCEforms']['config'];
+                                       break;
+                               } elseif (isset($ds['el'][$fieldName]['TCEforms']['config'])) {
+                                       $fieldConfig = $ds['el'][$fieldName]['TCEforms']['config'];
+                                       break;
+                               } else {
+                                       $fieldConfig = $this->getNestedDsFieldConfig($ds, $fieldName);
+                               }
+                       }
+               }
+               return $fieldConfig;
+       }
+
+       /**
         * Ajax handler for the "suggest" feature in TCEforms.
         *
         * @param array $params The parameters from the AJAX call
@@ -144,8 +171,8 @@ class SuggestElement {
                                $continue = TRUE;
                                foreach ($flexformDSArray as $sheet) {
                                        foreach ($sheet as $_ => $dataStructure) {
-                                               if (isset($dataStructure['ROOT']['el'][$flexformElement]['TCEforms']['config'])) {
-                                                       $fieldConfig = $dataStructure['ROOT']['el'][$flexformElement]['TCEforms']['config'];
+                                               $fieldConfig = $this->getNestedDsFieldConfig($dataStructure, $flexformElement);
+                                               if (count($fieldConfig) > 0) {
                                                        $continue = FALSE;
                                                        break;
                                                }
index 0f59806..136afe0 100644 (file)
@@ -94,7 +94,7 @@ TCEForms.Suggest = Class.create({
                        var rec_uid = arr[3];
                        var rec_field = arr[4];
 
-                       var formEl = 'data[' + rec_table + '][' + rec_uid + '][' + rec_field + ']';
+                       var formEl = this.objectId;
                        var suggestLabelNode = Element.select(this.escapeObjectId(item.id), '.suggest-label')[0];
                        var label = (suggestLabelNode.textContent ? suggestLabelNode.textContent : suggestLabelNode.innerText)
                        setFormValueFromBrowseWin(formEl, ins_table + '_' + ins_uid, label);