DEV: Allow topics to register default topic order criteria. (#7158)

DEV: Allow topics to register default topic order criteria. (#7158)

diff --git a/app/assets/javascripts/discourse/components/edit-category-settings.js.es6 b/app/assets/javascripts/discourse/components/edit-category-settings.js.es6
index 455418f..712aa67 100644
--- a/app/assets/javascripts/discourse/components/edit-category-settings.js.es6
+++ b/app/assets/javascripts/discourse/components/edit-category-settings.js.es6
@@ -2,6 +2,11 @@ import { setting } from "discourse/lib/computed";
 import { buildCategoryPanel } from "discourse/components/edit-category-panel";
 import computed from "ember-addons/ember-computed-decorators";
 
+const categorySortCriteria = [];
+export function addCategorySortCriteria(criteria) {
+  categorySortCriteria.push(criteria);
+}
+
 export default buildCategoryPanel("settings", {
   emailInEnabled: setting("email_in"),
   showPositionInput: setting("fixed_category_positions"),
@@ -64,10 +69,9 @@ export default buildCategoryPanel("settings", {
       "category",
       "created"
     ]
+      .concat(categorySortCriteria)
       .map(s => ({ name: I18n.t("category.sort_options." + s), value: s }))
-      .sort((a, b) => {
-        return a.name > b.name;
-      });
+      .sort((a, b) => a.name.localeCompare(b.name));
   },
 
   @computed
diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6
index 910b55f..62703f7 100644
--- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6
+++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6
@@ -41,9 +41,10 @@ import { disableNameSuppression } from "discourse/widgets/poster-name";
 import { registerCustomPostMessageCallback as registerCustomPostMessageCallback1 } from "discourse/controllers/topic";
 import Sharing from "discourse/lib/sharing";
 import { addComposerUploadHandler } from "discourse/components/composer-editor";
+import { addCategorySortCriteria } from "discourse/components/edit-category-settings";
 
 // If you add any methods to the API ensure you bump up this number
-const PLUGIN_API_VERSION = "0.8.29";
+const PLUGIN_API_VERSION = "0.8.30";
 
 class PluginApi {
   constructor(version, container) {
@@ -801,7 +802,6 @@ class PluginApi {
   }
 
   /**
-   *
    * Registers a function to handle uploads for specified file types
    * The normal uploading functionality will be bypassed if function returns
    * a falsy value.
@@ -818,6 +818,18 @@ class PluginApi {
   }
 
   /**
+   * Registers a criteria that can be used as default topic order on category
+   * pages.
+   *
+   * Example:
+   *
+   * categorySortCriteria("votes");
+   */
+  addCategorySortCriteria(criteria) {
+    addCategorySortCriteria(criteria);
+  }
+
+  /**
    * Registers a renderer that overrides the display of category links.
    *
    * Example:

GitHub sha: 91bd0bec