Skip to content

Instantly share code, notes, and snippets.

@ogrosko
Last active February 10, 2020 11:01
Show Gist options
  • Save ogrosko/f8154c9295099dc1a9094f282e11ed21 to your computer and use it in GitHub Desktop.
Save ogrosko/f8154c9295099dc1a9094f282e11ed21 to your computer and use it in GitHub Desktop.
Typo3 page tree flat sorting
/**
* @return array
*/
public function getSortingMatrix(): array
{
$matrix = [];
$rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $this->getUid())->get();
foreach ($rootLine as $level => $item) {
$matrix[$level] = $item['sorting'];
}
return $matrix;
}
/**
* Sort pages based on sorting and accept tree sorting
*/
\usort($solutions, function ($a, $b) {
$verdict = 0;
$aMatrix = $a->getSortingMatrix();
$bMatrix = $b->getSortingMatrix();
foreach ($aMatrix as $level => $sorting) {
if ($sorting === $bMatrix[$level]) {
continue;
}
$verdict = $sorting - $bMatrix[$level];
}
return $verdict;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment