From 2a81967a3c5c1c01d8e60aee014b926b0c6b07c8 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Wed, 24 May 2023 21:24:44 +0200 Subject: [PATCH] [BUGFIX] Sort entries in Table of Content plugin by orderlabel (#956) Co-authored-by: Sebastian Meyer --- .../Controller/TableOfContentsController.php | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Classes/Controller/TableOfContentsController.php b/Classes/Controller/TableOfContentsController.php index 8c5c4269d..f0d7e554b 100644 --- a/Classes/Controller/TableOfContentsController.php +++ b/Classes/Controller/TableOfContentsController.php @@ -113,6 +113,7 @@ protected function makeMenuArray() } } } + $this->sortMenu($menuArray); return $menuArray; } @@ -135,7 +136,7 @@ protected function getMenuEntry(array $entry, $recursive = false) $entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; $entryArray['volume'] = $entry['volume']; $entryArray['orderlabel'] = $entry['orderlabel']; - $entryArray['type'] = Helper::translate($entry['type'], 'tx_dlf_structures', $this->settings['storagePid']); + $entryArray['type'] = $this->getTranslatedType($entry['type']); $entryArray['pagination'] = htmlspecialchars($entry['pagination']); $entryArray['_OVERRIDE_HREF'] = ''; $entryArray['doNotLinkIt'] = 1; @@ -237,4 +238,39 @@ protected function resolveMenuEntry($entry) return $entry; } + + /** + * Get translated type of entry. + * + * @param array $type + * @return string + */ + private function getTranslatedType($type) { + return Helper::translate($type, 'tx_dlf_structures', $this->settings['storagePid']); + } + + /** + * Sort menu by orderlabel - currently implemented for newspaper. + * //TODO: add for years + * + * @param array &$menu + * @return void + */ + private function sortMenu(&$menu) { + if ($menu[0]['type'] == $this->getTranslatedType("newspaper")) { + $this->sortMenuForNewspapers($menu); + } + } + + /** + * Sort menu years of the newspaper by orderlabel. + * + * @param array &$menu + * @return void + */ + private function sortMenuForNewspapers(&$menu) { + usort($menu[0]['_SUB_MENU'], function ($firstYear, $secondYear) { + return $firstYear['orderlabel'] <=> $secondYear['orderlabel']; + }); + } }