[TASK] Respect default_sortby in TCA foreign table queries 74/61474/5
authorChristoph Lehmann <christoph.lehmann@networkteam.com>
Wed, 7 Aug 2019 22:21:24 +0000 (00:21 +0200)
committerTobi Kretschmann <tobi@tobishome.de>
Wed, 15 Jan 2020 13:35:54 +0000 (14:35 +0100)
Currently an ORDER BY clause is needed in foreign_table_where
to get a sorting. This makes it obsolete in favor of the default
tables sorting through default_sortby. This concerns TCA's
select and tree fields.

Resolves: #70677
Releases: master,9.5
Change-Id: I259211f7812bfa39e9744e71265577524911082d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61474
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Tested-by: Jörg Bösche <typo3@joergboesche.de>
Tested-by: Felix P. <f.pachowsky@neusta.de>
Tested-by: Steffen Frese <steffenf14@gmail.com>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Felix P. <f.pachowsky@neusta.de>
Reviewed-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Reviewed-by: Steffen Frese <steffenf14@gmail.com>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php

index f7d0a6b..b2fedd1 100644 (file)
@@ -1004,6 +1004,13 @@ abstract class AbstractItemProvider
                 [$fieldName, $order] = $orderPair;
                 $queryBuilder->addOrderBy($fieldName, $order);
             }
+        } elseif (!empty($GLOBALS['TCA'][$foreignTableName]['ctrl']['default_sortby'])) {
+            $orderByClauses = QueryHelper::parseOrderBy($GLOBALS['TCA'][$foreignTableName]['ctrl']['default_sortby']);
+            foreach ($orderByClauses as $orderByClause) {
+                if (!empty($orderByClause[0])) {
+                    $queryBuilder->addOrderBy($orderByClause[0], $orderByClause[1]);
+                }
+            }
         }
 
         if (!empty($foreignTableClauseArray['LIMIT'])) {