mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
add new hook action:plugins.firehook
This commit is contained in:
@@ -84,19 +84,31 @@ module.exports = function (Plugins) {
|
|||||||
|
|
||||||
Plugins.fireHook = function (hook, params, callback) {
|
Plugins.fireHook = function (hook, params, callback) {
|
||||||
callback = typeof callback === 'function' ? callback : function () {};
|
callback = typeof callback === 'function' ? callback : function () {};
|
||||||
|
function done(err, result) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
if (hook !== 'action:plugins.firehook') {
|
||||||
|
Plugins.fireHook('action:plugins.firehook', { hook: hook, params: params });
|
||||||
|
}
|
||||||
|
if (result) {
|
||||||
|
callback(null, result);
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
var hookList = Plugins.loadedHooks[hook];
|
var hookList = Plugins.loadedHooks[hook];
|
||||||
var hookType = hook.split(':')[0];
|
var hookType = hook.split(':')[0];
|
||||||
winston.verbose('[plugins/fireHook]', hook);
|
winston.verbose('[plugins/fireHook]', hook);
|
||||||
switch (hookType) {
|
switch (hookType) {
|
||||||
case 'filter':
|
case 'filter':
|
||||||
fireFilterHook(hook, hookList, params, callback);
|
fireFilterHook(hook, hookList, params, done);
|
||||||
break;
|
break;
|
||||||
case 'action':
|
case 'action':
|
||||||
fireActionHook(hook, hookList, params, callback);
|
fireActionHook(hook, hookList, params, done);
|
||||||
break;
|
break;
|
||||||
case 'static':
|
case 'static':
|
||||||
fireStaticHook(hook, hookList, params, callback);
|
fireStaticHook(hook, hookList, params, done);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
winston.warn('[plugins] Unknown hookType: ' + hookType + ', hook : ' + hook);
|
winston.warn('[plugins] Unknown hookType: ' + hookType + ', hook : ' + hook);
|
||||||
|
|||||||
Reference in New Issue
Block a user