Class connector for adding button to post

I am trying to make colne of this plugin: Add a button at the bottom of a topic, visible to a specific group: discourse-topic-group-button
I am trying to add button at every single post , not topics.
But I do not know how to set my class connectors for injecting buttons or icons into post.
If I understand well plugin I noticed using this connector over this
assets/javascripts/discourse/templates/connectors/after-topic-footer-main-buttons/custom-public-button.hbs
If I want to add button in post menu how my connector should looks like?

1 Like

If you want to add a button to the post menu then you’ll need something a little bit different since posts are widgets.

You would need to add something like this to your theme / plugin.

api.addPostMenuButton("my-button", () => {
  return {
    action: "someAction",
    icon: "someIcon",
    className: "someClass",
    title: "some title",
  };
});

The plugin API has a method for adding new buttons that makes this relatively easy.

https://github.com/discourse/discourse/blob/7a2e8d3ead63c7d99e1069fc7823e933f931ba85/app/assets/javascripts/discourse/app/lib/plugin-api.js#L371-L392

This theme component uses that method to add a new button to that menu based on some conditions and defines a new action, so have a look here

https://github.com/discourse/raw-post-button

7 Likes