diff --git a/CHANGELOG.md b/CHANGELOG.md index a3a8db04f9b..916fa4db9d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## DEV + * Correctly apply the sorting flags in the list and parent view (see contao/core-bundle#1536). + * Purge the search index when a page alias changes (see #472). * Show only newsletter channels with redirect page in the newsletter list module (see #494). * Use `scssphp/scssphp` instead of `leafo/scssphp` (see #506). * Hide empty legends in the `member_grouped.html5` template (see #514). diff --git a/calendar-bundle/src/Resources/contao/dca/tl_calendar_events.php b/calendar-bundle/src/Resources/contao/dca/tl_calendar_events.php index dfe2e1c1462..f223fc1353a 100644 --- a/calendar-bundle/src/Resources/contao/dca/tl_calendar_events.php +++ b/calendar-bundle/src/Resources/contao/dca/tl_calendar_events.php @@ -56,7 +56,7 @@ 'sorting' => array ( 'mode' => 4, - 'fields' => array('startTime DESC'), + 'fields' => array('startTime'), 'headerFields' => array('title', 'jumpTo', 'tstamp', 'protected', 'allowComments'), 'panelLayout' => 'filter;sort,search,limit', 'child_record_callback' => array('tl_calendar_events', 'listEvents') diff --git a/comments-bundle/src/Resources/contao/dca/tl_comments.php b/comments-bundle/src/Resources/contao/dca/tl_comments.php index e1ace33167a..a5b1086914f 100644 --- a/comments-bundle/src/Resources/contao/dca/tl_comments.php +++ b/comments-bundle/src/Resources/contao/dca/tl_comments.php @@ -43,8 +43,7 @@ 'sorting' => array ( 'mode' => 2, - 'fields' => array('date DESC'), - 'flag' => 8, + 'fields' => array('date'), 'panelLayout' => 'filter;sort,search,limit' ), 'label' => array diff --git a/core-bundle/src/Resources/contao/dca/tl_article.php b/core-bundle/src/Resources/contao/dca/tl_article.php index 7e053c89c58..589ee1fbb47 100644 --- a/core-bundle/src/Resources/contao/dca/tl_article.php +++ b/core-bundle/src/Resources/contao/dca/tl_article.php @@ -44,7 +44,6 @@ 'sorting' => array ( 'mode' => 6, - 'fields' => array('published DESC', 'title', 'author'), 'paste_button_callback' => array('tl_article', 'pasteArticle'), 'panelLayout' => 'filter;search' ), diff --git a/core-bundle/src/Resources/contao/dca/tl_log.php b/core-bundle/src/Resources/contao/dca/tl_log.php index b3678a95888..e7abd8373ed 100644 --- a/core-bundle/src/Resources/contao/dca/tl_log.php +++ b/core-bundle/src/Resources/contao/dca/tl_log.php @@ -33,7 +33,7 @@ 'sorting' => array ( 'mode' => 2, - 'fields' => array('tstamp DESC', 'id DESC'), + 'fields' => array('tstamp'), 'panelLayout' => 'filter;sort,search,limit' ), 'label' => array diff --git a/core-bundle/src/Resources/contao/dca/tl_member.php b/core-bundle/src/Resources/contao/dca/tl_member.php index 22ff1302efc..ad79985e7e9 100644 --- a/core-bundle/src/Resources/contao/dca/tl_member.php +++ b/core-bundle/src/Resources/contao/dca/tl_member.php @@ -44,8 +44,7 @@ 'sorting' => array ( 'mode' => 2, - 'fields' => array('dateAdded DESC'), - 'flag' => 1, + 'fields' => array('dateAdded'), 'panelLayout' => 'filter;sort,search,limit' ), 'label' => array diff --git a/core-bundle/src/Resources/contao/dca/tl_undo.php b/core-bundle/src/Resources/contao/dca/tl_undo.php index 7258d35ef84..abde074e56a 100644 --- a/core-bundle/src/Resources/contao/dca/tl_undo.php +++ b/core-bundle/src/Resources/contao/dca/tl_undo.php @@ -36,7 +36,7 @@ 'sorting' => array ( 'mode' => 2, - 'fields' => array('tstamp DESC'), + 'fields' => array('tstamp'), 'panelLayout' => 'sort,search,limit' ), 'label' => array diff --git a/core-bundle/src/Resources/contao/dca/tl_user.php b/core-bundle/src/Resources/contao/dca/tl_user.php index a2bd406fa73..1e88b8eb3c6 100644 --- a/core-bundle/src/Resources/contao/dca/tl_user.php +++ b/core-bundle/src/Resources/contao/dca/tl_user.php @@ -46,7 +46,7 @@ 'sorting' => array ( 'mode' => 2, - 'fields' => array('dateAdded DESC'), + 'fields' => array('dateAdded'), 'flag' => 1, 'panelLayout' => 'filter;sort,search,limit' ), diff --git a/core-bundle/src/Resources/contao/drivers/DC_Table.php b/core-bundle/src/Resources/contao/drivers/DC_Table.php index 6f91881bdb4..e7b64744f53 100644 --- a/core-bundle/src/Resources/contao/drivers/DC_Table.php +++ b/core-bundle/src/Resources/contao/drivers/DC_Table.php @@ -4313,6 +4313,14 @@ protected function parentView() // ORDER BY if (!empty($orderBy) && \is_array($orderBy)) { + foreach ($orderBy as $k=>$v) + { + if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['flag']) && ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['flag'] % 2) == 0) + { + $orderBy[$k] .= ' DESC'; + } + } + $query .= " ORDER BY " . implode(', ', $orderBy); } @@ -4617,8 +4625,23 @@ protected function listView() { list($key, $direction) = explode(' ', $v, 2); + // If there is no direction, check the global flag in sorting mode 1 or the field flag in all other sorting modes + if (!$direction) + { + if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 1 && isset($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag']) && ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] % 2) == 0) + { + $direction = 'DESC'; + } + elseif (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['flag']) && ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['flag'] % 2) == 0) + { + $direction = 'DESC'; + } + } + if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['eval']['findInSet']) { + $direction = null; + if (\is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options_callback'])) { $strClass = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options_callback'][0]; @@ -4645,7 +4668,12 @@ protected function listView() } elseif (\in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['flag'], array(5, 6, 7, 8, 9, 10))) { - $orderBy[$k] = "CAST($key AS SIGNED)" . ($direction ? " $direction" : ""); // see #5503 + $orderBy[$k] = "CAST($key AS SIGNED)"; // see #5503 + } + + if ($direction) + { + $orderBy[$k] = $key . ' ' . $direction; } } @@ -4672,11 +4700,6 @@ protected function listView() } } - if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 1 && ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] % 2) == 0) - { - $query .= " DESC"; - } - $objRowStmt = $this->Database->prepare($query); if ($this->limit != '') diff --git a/news-bundle/src/Resources/contao/dca/tl_news.php b/news-bundle/src/Resources/contao/dca/tl_news.php index cfab3d5de06..eecb340ba5e 100644 --- a/news-bundle/src/Resources/contao/dca/tl_news.php +++ b/news-bundle/src/Resources/contao/dca/tl_news.php @@ -56,7 +56,7 @@ 'sorting' => array ( 'mode' => 4, - 'fields' => array('date DESC'), + 'fields' => array('date'), 'headerFields' => array('title', 'jumpTo', 'tstamp', 'protected', 'allowComments'), 'panelLayout' => 'filter;sort,search,limit', 'child_record_callback' => array('tl_news', 'listNewsArticles'), diff --git a/newsletter-bundle/src/Resources/contao/dca/tl_newsletter.php b/newsletter-bundle/src/Resources/contao/dca/tl_newsletter.php index 7a2c5974e5e..e473c402ff7 100644 --- a/newsletter-bundle/src/Resources/contao/dca/tl_newsletter.php +++ b/newsletter-bundle/src/Resources/contao/dca/tl_newsletter.php @@ -37,7 +37,7 @@ 'sorting' => array ( 'mode' => 4, - 'fields' => array('sent', 'date DESC', 'tstamp DESC'), + 'fields' => array('sent', 'date'), 'headerFields' => array('title', 'jumpTo', 'tstamp', 'sender'), 'panelLayout' => 'filter;sort,search,limit', 'child_record_callback' => array('tl_newsletter', 'listNewsletters')