Skip to content

A platform for community discussion. Free, open, simple.

FIX: access correct name and description (#28353)

Joffrey JAFFEUXa5980ea63711
diff --git a/app/assets/javascripts/discourse/app/helpers/category-link.js b/app/assets/javascripts/discourse/app/helpers/category-link.js
index 9b65a52e38b..4181f9ee938 100644
--- a/app/assets/javascripts/discourse/app/helpers/category-link.js
+++ b/app/assets/javascripts/discourse/app/helpers/category-link.js
@@ -1,6 +1,7 @@
import { get } from "@ember/object";
import { htmlSafe } from "@ember/template";
import categoryVariables from "discourse/helpers/category-variables";
+import { applyValueTransformer } from "discourse/lib/transformer";
import { escapeExpression } from "discourse/lib/utilities";
import Category from "discourse/models/category";
import getURL from "discourse-common/lib/get-url";
@@ -112,7 +113,13 @@ function buildTopicCount(count) {
}
export function defaultCategoryLinkRenderer(category, opts) {
- let descriptionText = escapeExpression(get(category, "descriptionText"));
+ // not ideal as we have to call it manually and we pass a fake category object
+ // but there's not way around it for now
+ let descriptionText = applyValueTransformer(
+ "category-description-text",
+ escapeExpression(get(category, "description_text")),
+ { category }
+ );
let restricted = get(category, "read_restricted");
let url = opts.url
? opts.url
@@ -156,7 +163,13 @@ export function defaultCategoryLinkRenderer(category, opts) {
${descriptionText ? 'title="' + descriptionText + '" ' : ""}
>`;
- let categoryName = escapeExpression(get(category, "displayName"));
+ // not ideal as we have to call it manually and we pass a fake category object
+ // but there's not way around it for now
+ let categoryName = applyValueTransformer(
+ "category-display-name",
+ escapeExpression(get(category, "name")),
+ { category }
+ );
if (siteSettings.support_mixed_text_direction) {
categoryDir = 'dir="auto"';
diff --git a/app/assets/javascripts/discourse/tests/integration/helpers/category-link-test.js b/app/assets/javascripts/discourse/tests/integration/helpers/category-link-test.js
new file mode 100644
index 00000000000..8188d2d4d03
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/integration/helpers/category-link-test.js
@@ -0,0 +1,22 @@
+import { render } from "@ember/test-helpers";
+import { hbs } from "ember-cli-htmlbars";
+import { assert, module, test } from "qunit";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+
+module("Integration | Helper | category-link", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("name", async function () {
+ await render(hbs`{{category-link (hash name="foo")}}`);
+
+ assert.dom(".badge-category__name").hasText("foo");
+ });
+
+ test("description_text", async function () {
+ await render(
+ hbs`{{category-link (hash name="foo" description_text="bar")}}`
+ );
+
+ assert.dom(".badge-category").hasAttribute("title", "bar");
+ });
+});