In a Dev category thread titled “Modify ‘New Topic’ button default behavior,” jotamartos seeks help modifying the “New Topic” button’s behavior in Discourse 2.6.1, having previously succeeded in version 1.8.0. Their plugin overrides Ember actions via controller reopens, but the main site’s button no longer responds. pfaffman offers a tangential resource on custom fields, which jotamartos clarifies doesn’t address their need to run custom JavaScript on button click. After further investigation, jotamartos resolves the issue by updating the controller import to discourse/components/d-navigation and overriding the clickCreateTopicButton action instead of createTopic. The fix works for both the main navigation and search results, restoring their custom menu functionality. pfaffman celebrates the solution, acknowledging the ongoing mystery of Discourse’s front-end structure.
I’m trying to modify the default behavior of the “New Topic” button in Discourse 2.6.1. I have a custom plugin that modifies the default Ember actions to run my function. It worked properly when using a previous version of Discourse (1.8.0) but I can’t find how to get the same result in the new version. The code is the following one:
The first controller controller defined the main site’s actions (which doesn’t work in the new version) and the second one defined the actions to run when running a search in the app (and it works in the new version as well).
I saw that the “New Topic” buttons are created using the “createTopic” and “clickCreateTopicButton” actions but none of them work in the main site. Do I need to modify another action or do we need to use a different controller?
Thank you for the suggestion. However, if I’m not mistaken, that plugin allows you add a new custom field to a topic but what I want to do is to run my own javascript code when clicking on the “New Topic” button. I think my issue is basically related to the Discourse’s controller to use, the name of the function that is run and how to overwrite that function. Can you shed some light here?
Well, darn. Sorry. I was thinking that it had some javascript code in it (e.g., in discourse-topic-custom-fields/assets/javascripts/discourse) that might be helpful in seeing how to wire that stuff up. I’m still not very good at the front end stuff, so I’m afraid that was my best free answer.