I’m writing a plugin to extend badge functionality. When the “save” button is pressed on the admin badge page, I want to execute some additional code.
Discourse Javascript:
Discourse hbs:
My code discourse/plugins/discourse-badge-extension/assets/javascripts/discourse/initializers/modify-admin-badges-show-controller.js
:
import { withPluginApi } from 'discourse/lib/plugin-api';
export default {
name: 'modify-admin-badges-show',
initialize() {
withPluginApi('0.8', api => {
api.modifyClass('controller:admin-badges/show', {
pluginId: 'discourse-badge-extension',
actions: {
save() {
console.log("Custom pre-save logic triggered");
alert("Pre-save logic");
this._super(...arguments); // Call the original save method
console.log("Post-save logic triggered");
alert("Post-save logic");
},
}
});
alert("Hello! I am an alert box!!");
});
}
};
It’s an initializer.
- The alert box
"Hello! I am an alert box!!"
is triggered, indicating the code is being run on reload. - Neither the console.log lines nor the alerts run on saving, indicating the overriding is not working?
- the controller name does not give an error
controller:admin-badges/show
(but intentionally adding a typo does, suggesting I am targeting a real controller)
It should be easy to repo given it’s just one initializer. What am I doing wrong???