DEV: Plugin API function to add items to quick access profile (#10182)

This commit is contained in:
Mark VanLandingham
2020-07-07 13:53:40 -05:00
committed by GitHub
parent d09a953f53
commit 81fe8a50d4
2 changed files with 26 additions and 1 deletions

View File

@ -56,6 +56,7 @@ import { addExtraIconRenderer } from "discourse/helpers/category-link";
import { queryRegistry } from "discourse/widgets/widget";
import Composer from "discourse/models/composer";
import { on } from "@ember/object/evented";
import { addQuickAccessProfileItem } from "discourse/widgets/quick-access-profile";
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
// If you add any methods to the API ensure you bump up this number
@ -1157,6 +1158,22 @@ class PluginApi {
addToHeaderIcons(icon) {
addToHeaderIcons(icon);
}
/**
* Adds an item to the quick access profile panel, before "Log Out".
*
* ```
* api.addQuickAccessProfileItem({
* icon: "pencil-alt",
* href: "/somewhere",
* content: I18n.t("user.somewhere")
* })
* ```
*
**/
addQuickAccessProfileItem(item) {
addQuickAccessProfileItem(item);
}
}
let _pluginv01;

View File

@ -3,6 +3,12 @@ import QuickAccessPanel from "discourse/widgets/quick-access-panel";
import { createWidgetFrom } from "discourse/widgets/widget";
import { Promise } from "rsvp";
const _extraItems = [];
export function addQuickAccessProfileItem(item) {
_extraItems.push(item);
}
createWidgetFrom(QuickAccessPanel, "quick-access-profile", {
tagName: "div.quick-access-panel.quick-access-profile",
@ -22,10 +28,12 @@ createWidgetFrom(QuickAccessPanel, "quick-access-profile", {
},
_getItems() {
const items = this._getDefaultItems();
let items = this._getDefaultItems();
if (this._showToggleAnonymousButton()) {
items.push(this._toggleAnonymousButton());
}
items = items.concat(_extraItems);
if (this.attrs.showLogoutButton) {
items.push(this._logOutButton());
}