Skip to content

Commit

Permalink
[BUGFIX] Sort entries in Table of Content plugin by orderlabel (#956)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Meyer <[email protected]>
  • Loading branch information
beatrycze-volk and sebastian-meyer committed Sep 15, 2023
1 parent 3a0a369 commit 87af845
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Classes/Controller/TableOfContentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected function makeMenuArray()
}
}
}
$this->sortMenu($menuArray);
return $menuArray;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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'];
});
}
}

0 comments on commit 87af845

Please sign in to comment.