Skip to content

Commit a5d603b

Browse files
authored
Merge pull request #54 from sitegeist/sorting
Sort vocabularies and taxonomies alphabetically
2 parents dad0224 + db8332f commit a5d603b

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Classes/Controller/ModuleController.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ public function indexAction(NodeInterface $root = null)
117117
'defaultNode' => $this->getNodeInDefaultDimensions($vocabulary)
118118
];
119119
}
120+
usort($vocabularies, function (array $vocabularyA, array $vocabularyB) {
121+
return strcmp(
122+
$vocabularyA['node']->getProperty('title') ?: '',
123+
$vocabularyB['node']->getProperty('title') ?: ''
124+
);
125+
});
120126

121127
$this->view->assign('taxonomyRoot', $root);
122128
$this->view->assign('vocabularies', $vocabularies);
@@ -245,7 +251,14 @@ public function vocabularyAction(NodeInterface $vocabulary)
245251
$this->view->assign('taxonomyRoot', $root);
246252
$this->view->assign('vocabulary', $vocabulary);
247253
$this->view->assign('defaultVocabulary', $this->getNodeInDefaultDimensions($vocabulary));
248-
$this->view->assign('taxonomies', $this->fetchChildTaxonomies($vocabulary));
254+
$taxonomies = $this->fetchChildTaxonomies($vocabulary);
255+
usort($taxonomies, function (array $taxonomyA, array $taxonomyB) {
256+
return strcmp(
257+
$taxonomyA['node']->getProperty('title') ?: '',
258+
$taxonomyB['node']->getProperty('title') ?: ''
259+
);
260+
});
261+
$this->view->assign('taxonomies', $taxonomies);
249262
}
250263

251264
/**

Classes/Service/TaxonomyService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ public function getTaxonomyTreeAsArray(NodeInterface $startingPoint): array
213213
foreach ($startingPoint->getChildNodes() as $childNode) {
214214
$result['children'][] = $this->getTaxonomyTreeAsArray($childNode);
215215
}
216+
usort($result['children'], function (array $childA, array $childB) {
217+
return strcmp(
218+
$childA['title'] ?: '',
219+
$childB['title'] ?: ''
220+
);
221+
});
216222

217223
return $result;
218224
}

0 commit comments

Comments
 (0)