2,446 downloads
2 stars
v1.0.0
Updated
README
FoF Forum Widgets
A Flarum extension. Core framework for managing forum widgets.


[!NOTE] This package was previously maintained as
afrux/forum-widgets-coreby @SychO9. It has been transferred to FriendsOfFlarum and is now published asfof/forum-widgets-core. Thecomposer.jsonreplacefield ensures existing installs upgrade transparently — no manual removal needed.
Installation
Remember that this is just a forum widgets editor, it doesn't actually come with any widgets.
composer require fof/forum-widgets-core:"*"
Migrating from afrux/forum-widgets-core
If you currently have afrux/forum-widgets-core installed, run:
composer require fof/forum-widgets-core:"*"
composer remove afrux/forum-widgets-core
php flarum cache:clear
Updating
composer update fof/forum-widgets-core:"*"
php flarum migrate
php flarum cache:clear
Extend
Extension developers wanting to create widgets with this small framework, the following explains how you can register a new widget, for now you should only register one widget per extension.
- Require this extension in your extension's
composer.json:
"require": {
"flarum/core": "^2.0.0",
"fof/forum-widgets-core": "^2.0.0"
}
- Create your widget's component in
common/componentsby extending the baseWidgetcomponent:
import Widget from 'ext:fof/forum-widgets-core/common/components/Widget';
export default class MyWidget extends Widget {
className() {
// Custom class name.
// Use "FofWidgets-Widget--flat" for a flat widget (no container block).
return 'MyWidget';
}
icon() {
return 'fas fa-circle';
}
title() {
return app.translator.trans('my-extension.forum.widget.title');
}
content() {
return <div className="MyWidget-content">...</div>;
}
}
- Register your widget in both frontends. Create
common/registerWidget.js:
import Widgets from 'ext:fof/forum-widgets-core/common/extend/Widgets';
import MyWidget from './components/MyWidget';
export default function (app) {
new Widgets()
.add({
key: 'myWidget',
component: MyWidget,
// Can be a callback: () => app.forum.attribute('mySetting')
isDisabled: false,
// Is this a one-time-use widget? Leave true if unsure.
isUnique: true,
// Default values, overridable by the admin.
placement: 'end',
position: 1,
})
.extend(app, 'my-extension-id');
}
Then in both admin/index.js and forum/index.js:
import registerWidget from '../common/registerWidget';
app.initializers.add('my-extension-id', () => {
registerWidget(app);
});
- For TypeScript, add this to the
pathskey in yourtsconfig.json:
"ext:fof/forum-widgets-core/*": ["../vendor/fof/forum-widgets-core/js/dist-typings/*"]