From 8b366b45dbd60d6b21203908d1a6b3a613e97524 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 14 Dec 2024 16:43:36 +0000 Subject: [PATCH] [tag_list] fix sorting for tag lists, fixes #1355 --- ext/tag_list/theme.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/ext/tag_list/theme.php b/ext/tag_list/theme.php index 353cf7636..051a69885 100644 --- a/ext/tag_list/theme.php +++ b/ext/tag_list/theme.php @@ -35,6 +35,23 @@ protected function get_tag_list_preamble(): HTMLElement ); } + /** + * @param array $tag_infos + * @param string[] $search + */ + private function get_tag_list_html(array $tag_infos, string $sort, array $search = []): HTMLElement + { + if ($sort === TagListConfig::SORT_ALPHABETICAL) { + usort($tag_infos, fn ($a, $b) => strcasecmp($a['tag'], $b['tag'])); + } + + $table = $this->get_tag_list_preamble(); + foreach ($tag_infos as $row) { + $table->appendChild(self::build_tag_row($row, $search)); + } + return $table; + } + /** * @param array $tag_infos */ @@ -43,7 +60,7 @@ public function display_split_related_block(Page $page, array $tag_infos): void global $config; if ($config->get_string(TagListConfig::RELATED_SORT) == TagListConfig::SORT_ALPHABETICAL) { - asort($tag_infos); + usort($tag_infos, fn ($a, $b) => strcasecmp($a['tag'], $b['tag'])); } if (Extension::is_enabled(TagCategoriesInfo::KEY)) { @@ -68,7 +85,7 @@ public function display_split_related_block(Page $page, array $tag_infos): void $tag_categories_count[$category] += 1; } - asort($tag_categories_html); + ksort($tag_categories_html); foreach (array_keys($tag_categories_html) as $category) { if ($category == '') { $category_display_name = 'Tags'; @@ -84,23 +101,6 @@ public function display_split_related_block(Page $page, array $tag_infos): void } } - /** - * @param array $tag_infos - * @param string[] $search - */ - private function get_tag_list_html(array $tag_infos, string $sort, array $search = []): HTMLElement - { - if ($sort == TagListConfig::SORT_ALPHABETICAL) { - asort($tag_infos); - } - - $table = $this->get_tag_list_preamble(); - foreach ($tag_infos as $row) { - $table->appendChild(self::build_tag_row($row, $search)); - } - return $table; - } - /** * @param array $tag_infos */