e.g.
api.addCommunitySectionLink({
name: "intersection-navigator",
route:"tags.intersection",
title: I18n.t("tag_intersection_navigator.link.title"),
text: I18n.t("tag_intersection_navigator.link.text")
})
… will fail because that route requires a tag_id.
I’ve tried adding:
params: { tag_id: siteSettings.discourse_tag_intersection_navigator_all_word },
model: { tag_id: siteSettings.discourse_tag_intersection_navigator_all_word },
… but I strongly suspect this isn’t processed as necessary by the api …
4 Likes
Specifically, I think it’s here: discourse/app/assets/javascripts/discourse/app/lib/sidebar/custom-community-section-links.js at d0c3f3b8fe6905e7e33ae4944cdf44c11ccc0df6 · discourse/discourse · GitHub
if we add this it should work:
get models() {
return args.models;
}
3 Likes
Oh and since there’s a typeof args === "function"
condition, you could do something like this immediately:
api.addCommunitySectionLink((Base) =>
class CustomLink extends Base {
get name() {
return "intersection-navigator";
}
get route() {
return "tag.show";
}
get models() {
return ["tagid"];
}
get title() {
return I18n.t("tag_intersection_navigator.link.title");
}
get text() {
return I18n.t("tag_intersection_navigator.link.text");
}
}
);
1 Like
yes, that’s what I’m already doing … but there’s some funny later in the process
1 Like
For some reason, this isn’t quite it and I’m getting some complaint about lack of postStream
upon click:
api.addCommunitySectionLink((baseSectionLink) => {
return class CustomSectionLink extends baseSectionLink {
get name() {
return "intersection-navigator";
}
get route() {
return "tags.intersection";
}
get models() {
return [{tag_id: siteSettings.discourse_tag_intersection_navigator_all_word}];
}
get title() {
return I18n.t("tag_intersection_navigator.link.title")
}
get text() {
return I18n.t("tag_intersection_navigator.link.text");
}
};
});
It’s almost as if you need to include the model for the current route, which is weird!
1 Like
what’s the output of that setting? it seems to work ok when I manually do:
get models() {
return ["featured", "tv"];
}
2 Likes
yes, that works, that’s really helpful, thanks!
the setting is just a string. I was over-thinking it I think.
the name “models” for the query params isn’t 100% intuitive though?
Your PR will make this much neater, cheers!
2 Likes
yeah it wasn’t clear to me at first either, but it’s because in the end it uses Ember’s LinkTo component, which expects a model argument…
1 Like