Skip to content

Commit

Permalink
Merge pull request #54 from sitegeist/sorting
Browse files Browse the repository at this point in the history
Sort vocabularies and taxonomies alphabetically
  • Loading branch information
nezaniel authored Apr 5, 2022
2 parents dad0224 + db8332f commit a5d603b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public function indexAction(NodeInterface $root = null)
'defaultNode' => $this->getNodeInDefaultDimensions($vocabulary)
];
}
usort($vocabularies, function (array $vocabularyA, array $vocabularyB) {
return strcmp(
$vocabularyA['node']->getProperty('title') ?: '',
$vocabularyB['node']->getProperty('title') ?: ''
);
});

$this->view->assign('taxonomyRoot', $root);
$this->view->assign('vocabularies', $vocabularies);
Expand Down Expand Up @@ -245,7 +251,14 @@ public function vocabularyAction(NodeInterface $vocabulary)
$this->view->assign('taxonomyRoot', $root);
$this->view->assign('vocabulary', $vocabulary);
$this->view->assign('defaultVocabulary', $this->getNodeInDefaultDimensions($vocabulary));
$this->view->assign('taxonomies', $this->fetchChildTaxonomies($vocabulary));
$taxonomies = $this->fetchChildTaxonomies($vocabulary);
usort($taxonomies, function (array $taxonomyA, array $taxonomyB) {
return strcmp(
$taxonomyA['node']->getProperty('title') ?: '',
$taxonomyB['node']->getProperty('title') ?: ''
);
});
$this->view->assign('taxonomies', $taxonomies);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions Classes/Service/TaxonomyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ public function getTaxonomyTreeAsArray(NodeInterface $startingPoint): array
foreach ($startingPoint->getChildNodes() as $childNode) {
$result['children'][] = $this->getTaxonomyTreeAsArray($childNode);
}
usort($result['children'], function (array $childA, array $childB) {
return strcmp(
$childA['title'] ?: '',
$childB['title'] ?: ''
);
});

return $result;
}
Expand Down

0 comments on commit a5d603b

Please sign in to comment.