[BUGFIX] Add possibility to use Wizards->Suggest in FlexForms
authorTolleiv Nietsch <info@tolleiv.de>
Mon, 10 Oct 2011 01:58:07 +0000 (03:58 +0200)
committerGeorg Ringer <mail@ringerge.org>
Wed, 7 Dec 2011 08:15:58 +0000 (09:15 +0100)
The field names generated for the suggest wizard are
not compatible with "flex" fields. This changes loads
the datastructure for the field and expands the
field name as needed.

Change-Id: I8d25594ba0376f7d35aa7f52860cad975014cc0a
Fixes: #22231
Releases: 4.5, 4.6
Reviewed-on: http://review.typo3.org/5703
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
t3lib/tceforms/class.t3lib_tceforms_suggest.php

index f904f2e..450649a 100644 (file)
@@ -64,6 +64,13 @@ class t3lib_TCEforms_Suggest {
                $containerCssClass = $this->cssClass . ' ' . $this->cssClass . '-position-right';
                $suggestId = 'suggest-' . $table . '-' . $field . '-' . $row['uid'];
 
+               if ($GLOBALS['TCA'][$table]['columns'][$field]['config']['type'] === 'flex') {
+                       $fieldPattern = 'data[' . $table . '][' . $row['uid'] . '][';
+                       $flexformField = str_replace($fieldPattern, '', $fieldname);
+                       $flexformField = substr($flexformField, 0, -1);
+                       $field = str_replace(array(']['), '|', $flexformField);
+               }
+
                $selector = '
                <div class="' . $containerCssClass . '" id="' . $suggestId . '">
                        <input type="text" id="' . $fieldname . 'Suggest" value="' .
@@ -129,12 +136,40 @@ class t3lib_TCEforms_Suggest {
                $TSconfig = t3lib_BEfunc::getPagesTSconfig($pageId);
                $queryTables = array();
                $foreign_table_where = '';
-               $wizardConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config']['wizards']['suggest'];
-               if (isset($GLOBALS['TCA'][$table]['columns'][$field]['config']['allowed'])) {
-                       $queryTables = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$field]['config']['allowed']);
-               } elseif (isset($GLOBALS['TCA'][$table]['columns'][$field]['config']['foreign_table'])) {
-                       $queryTables = array($GLOBALS['TCA'][$table]['columns'][$field]['config']['foreign_table']);
-                       $foreign_table_where = $GLOBALS['TCA'][$table]['columns'][$field]['config']['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 = t3lib_BEfunc::getFlexFormDS($flexfieldTCAConfig, $row, $table);
+                               $flexformDSArray = t3lib_div::resolveAllSheetsInDS($flexformDSArray);
+                               $flexformElement = $parts[count($parts) - 2];
+                               $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'];
+                                                       $continue = FALSE;
+                                                       break;
+                                               }
+                                       }
+                                       if (!$continue) {
+                                               break;
+                                       }
+                               }
+                               $field = str_replace('|', '][', $field);
+                       }
+               }
+
+               $wizardConfig = $fieldConfig['wizards']['suggest'];
+
+               if (isset($fieldConfig['allowed'])) {
+                       $queryTables = t3lib_div::trimExplode(',', $fieldConfig['allowed']);
+               } elseif (isset($fieldConfig['foreign_table'])) {
+                       $queryTables = array($fieldConfig['foreign_table']);
+                       $foreign_table_where = $fieldConfig['foreign_table_where'];
                                // strip ORDER BY clause
                        $foreign_table_where = trim(preg_replace('/ORDER[[:space:]]+BY.*/i', '', $foreign_table_where));
                }