stevenpslade encountered an error while updating a plugin due to the removal of the discourse/components/post-menu object. The plugin previously modified the PostMenu component to customize like button styles and redirect logged-out users to a specific URL upon interaction. zogstrip asked for clarification on the plugin’s purpose, while eviltrout advised migrating to the new client-side Discourse Plugin API, specifically suggesting the use of addPostMenuButton. joebuhlig clarified that the component had moved to a widget, prompting eviltrout to suggest using api.attachWidgetAction to overwrite existing widget actions like ‘like’ instead of adding new buttons. stevenpslade then inquired about positioning new buttons beyond the available ‘first’ and ‘last’ options. eviltrout explained the complexity of the hidden icon section and welcomed a pull request to add a ‘second’ position. stevenpslade located the relevant logic in the repository and subsequently submitted a PR to implement the requested feature 13.
I have to fully read the new plugin api format but my first problem actually has to do with this error:
The discourse/components/post-menu object has been removed from Discourse and your plugin needs to be updated.
PostMenu is a pretty important one and as far as I can tell does exist upon searching the Discourse repo on github. This is what is in the plugin:
import PostMenu from 'discourse/components/post-menu';
import StringBuffer from 'discourse/mixins/string-buffer';
import { iconHTML } from 'discourse/helpers/fa-icon';
import ComposerController from 'discourse/controllers/composer';
…some code inbetween…
PostMenu.reopen({
buttonForLike() {
const likeAction = this.get('post.likeAction');
if (!likeAction) { return; }
var className = likeAction.get('acted') ? 'has-like fade-out' : 'like';
var uId = Discourse.User.current().id;
if (uId%2 == 0) className+= " custom-like"
const opts = {className: className};
if (likeAction.get('canToggle')) {
const descKey = likeAction.get('acted') ? 'post.controls.undo_like' : 'post.controls.like';
return new Button('like', descKey, 'heart', opts);
} else if (likeAction.get('acted')) {
opts.disabled = true;
return new Button('like', 'post.controls.has_liked', 'heart', opts);
}
}
});
It does a couple of different things. For every other user, the like button style is different. The more important function of the plugin which isn’t shown in what I copied over, is that for logged out users, taking the action of liking or replying will redirect to a specific URL.
I believe he doesn’t want to add a new button but rather change the behavior of an existing one. I guess you could hide the original like button and add a custom one…
api.addPostMenuButton('coffee', () => {
return {
action: 'drinkCoffee',
icon: 'coffee',
className: 'coffee',
title: 'coffee.title',
position: 'first' // can be `first`, `last` or `second-last-hidden`
};
I have a question about the position argument for addPostMenuButton. How would one go about positioning the new button as second or third. Seems like if you can choose first or last, you might as well give ful control and be able to choose middle, etc as well.
Those positions are based on existing plugin behaviours I needed to duplicate. It turned out that they only needed those three options!
It is more complicated than it seems at first because there is a hidden chunk of icons in the middle. So if you said “middle” does that mean in the hidden section?
As for second, I’d happily accept a PR that adds that