[BUGFIX] processForeignTableClause no longer fails with select fields 25/43425/4
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Sat, 19 Sep 2015 09:20:50 +0000 (11:20 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 19 Sep 2015 12:09:38 +0000 (14:09 +0200)
When passed an array as field values, we pick the first entry as string

Resolves: #69952
Releases: master
Change-Id: Iebb0a340721f769c838a5247b30de1a41050c690
Reviewed-on: http://review.typo3.org/43425
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaSelectItems.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php

index 364a24f..f74472b 100644 (file)
@@ -888,6 +888,11 @@ class TcaSelectItems extends AbstractItemProvider implements FormDataProviderInt
                                                $whereClauseSubParts = explode('###', $value, 2);
                                                // @todo: Throw exception if there is no value? What happens for NEW records?
                                                $rowFieldValue = $result['databaseRow'][$whereClauseSubParts[0]];
+                                               if (is_array($rowFieldValue)) {
+                                                       // If a select or group field is used here, it may have been processed already and
+                                                       // is now an array. Use first selected value in this case.
+                                                       $rowFieldValue = $rowFieldValue[0];
+                                               }
                                                if (substr($whereClauseParts[0], -1) === '\'' && $whereClauseSubParts[1][0] === '\'') {
                                                        $whereClauseParts[$key] = $database->quoteStr($rowFieldValue, $foreignTableName) . $whereClauseSubParts[1];
                                                } else {
index ab4a7ab..079b0fa 100644 (file)
@@ -1119,6 +1119,17 @@ class TcaSelectItemsTest extends UnitTestCase {
                                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.title=\'rowFieldValue\'',
                                [],
                        ],
+                       'replace REC_FIELD fullQuoteWithArray' => [
+                               'AND fTable.title=###REC_FIELD_rowFieldThree###',
+                               'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.title=\'rowFieldThreeValue\'',
+                               [
+                                       'databaseRow' => [
+                                               'rowFieldThree' => [
+                                                       0 => 'rowFieldThreeValue'
+                                               ]
+                                       ],
+                               ],
+                       ],
                        'replace REC_FIELD multiple markers' => [
                                'AND fTable.title=\'###REC_FIELD_rowField###\' AND fTable.pid=###REC_FIELD_rowFieldTwo###',
                                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.title=\'rowFieldValue\' AND fTable.pid=\'rowFieldTwoValue\'',