diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 index e7118383597..e2e79d5b04b 100644 --- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 +++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 @@ -15,9 +15,10 @@ import { extraConnectorClass } from 'discourse/lib/plugin-connectors'; import { addPostSmallActionIcon } from 'discourse/widgets/post-small-action'; import { addDiscoveryQueryParam } from 'discourse/controllers/discovery-sortable'; import { addTagsHtmlCallback } from 'discourse/lib/render-tags'; +import { addUserMenuGlyph } from 'discourse/widgets/user-menu'; // If you add any methods to the API ensure you bump up this number -const PLUGIN_API_VERSION = '0.8.2'; +const PLUGIN_API_VERSION = '0.8.3'; class PluginApi { constructor(version, container) { @@ -399,10 +400,30 @@ class PluginApi { * } * } * + * api.addTagsHtmlCallback(callback); + * **/ addTagsHtmlCallback(callback) { addTagsHtmlCallback(callback); }; + + /** + * Adds a glyph to user menu after bookmarks + * WARNING: there is limited space there + * + * example: + * + * api.addUserMenuGlyph({ + * label: 'awesome.label', + * className: 'my-class', + * icon: 'my-icon', + * href: `/some/path` + * }); + * + */ + addUserMenuGlyph(glyph) { + addUserMenuGlyph(glyph); + }; } let _pluginv01; diff --git a/app/assets/javascripts/discourse/widgets/user-menu.js.es6 b/app/assets/javascripts/discourse/widgets/user-menu.js.es6 index 4a6f2b21c84..43a57c81d6d 100644 --- a/app/assets/javascripts/discourse/widgets/user-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/user-menu.js.es6 @@ -1,6 +1,13 @@ import { createWidget } from 'discourse/widgets/widget'; import { h } from 'virtual-dom'; +let extraGlyphs; + +export function addUserMenuGlyph(glyph) { + extraGlyphs = extraGlyphs || []; + extraGlyphs.push(glyph); +} + createWidget('user-menu-links', { tagName: 'div.menu-links-header', @@ -13,10 +20,18 @@ createWidget('user-menu-links', { isAnon; const path = attrs.path; - const glyphs = [{ label: 'user.bookmarks', + const glyphs = []; + + if (extraGlyphs) { + // yes glyphs.push(...extraGlyphs) is nicer, but pulling in + // _toConsumableArray seems totally uneeded here + glyphs.push.apply(glyphs, extraGlyphs); + } + + glyphs.push({ label: 'user.bookmarks', className: 'user-bookmarks-link', icon: 'bookmark', - href: `${path}/activity/bookmarks` }]; + href: `${path}/activity/bookmarks` }); if (siteSettings.enable_private_messages) { glyphs.push({ label: 'user.private_messages',