Skip to content

Commit 762c6f7

Browse files
tgxworldDiscourse CI
andauthored
DEV: Add backwards-compatible tag object handling (#50)
What is the problem? Discourse core PR #36678 changes tags from strings to objects with `{ id, name, slug }` format. The `iconTagRenderer` function in this theme calls `tag.toLowerCase()` which fails when `tag` is an object instead of a string. What is the solution? Extract the tag name using the same pattern as core's `defaultRenderTag`: `const tagName = typeof tag === "string" ? tag : tag.name` This maintains backwards compatibility with Discourse versions before the change. discourse/discourse#36678 Co-authored-by: Discourse CI <noreply@discourse.org>
1 parent 18d06a3 commit 762c6f7

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

javascripts/discourse/initializers/tag-icons.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ function iconTagRenderer(tag, params) {
88
// Get the rendered default tag markup.
99
const renderedTag = defaultRenderTag(tag, params);
1010

11+
// Handle both string tags (legacy) and object tags (new format: { id, name, slug })
12+
// This maintains backwards compatibility with Discourse versions before PR #36678
13+
const tagName = typeof tag === "string" ? tag : tag.name;
14+
1115
// Get the tag configuration list from the settings.
1216
const tagIconList = settings.tag_icon_list.split("|");
1317

1418
// Returns the tag configuration if found.
1519
const tagIconItem = tagIconList.find(
1620
(line) =>
1721
line.indexOf(",") > -1 &&
18-
tag.toLowerCase() === line.substr(0, line.indexOf(",")).toLowerCase()
22+
tagName.toLowerCase() === line.substr(0, line.indexOf(",")).toLowerCase()
1923
);
2024

2125
// Update the tag markup with an SVG icon, and inline-styles for the colors.

spec/system/tag_icons_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
fab!(:user)
1010

1111
let(:topic_page) { PageObjects::Pages::Topic.new }
12+
let(:topic_list) { PageObjects::Components::TopicList.new }
1213
let(:tag_icon) { PageObjects::Components::TagIcon.new }
1314
let!(:theme) { upload_theme_component }
1415

@@ -28,6 +29,16 @@
2829
)
2930
end
3031

32+
it "displays tag with icon on topics list page" do
33+
visit "/latest"
34+
expect(topic_list).to have_topic(topic)
35+
expect(tag_icon).to have_icon_for_tag(
36+
tag_name: "support",
37+
icon: "question-circle",
38+
color: "#ff0000",
39+
)
40+
end
41+
3142
it "displays tag without icon when not configured" do
3243
theme.update_setting(:tag_icon_list, "")
3344
theme.save!

0 commit comments

Comments
 (0)