mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
allow core to tap into NodeBB's hook system, closes #989
This commit is contained in:
@@ -269,11 +269,13 @@ var fs = require('fs'),
|
|||||||
|
|
||||||
var method;
|
var method;
|
||||||
|
|
||||||
if (data.hook && data.method && typeof data.method === 'string' && data.method.length > 0) {
|
if (data.hook && data.method) {
|
||||||
data.id = id;
|
data.id = id;
|
||||||
if (!data.priority) {
|
if (!data.priority) {
|
||||||
data.priority = 10;
|
data.priority = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof data.method === 'string' && data.method.length > 0) {
|
||||||
method = data.method.split('.').reduce(function(memo, prop) {
|
method = data.method.split('.').reduce(function(memo, prop) {
|
||||||
if (memo !== null && memo[prop]) {
|
if (memo !== null && memo[prop]) {
|
||||||
return memo[prop];
|
return memo[prop];
|
||||||
@@ -283,14 +285,18 @@ var fs = require('fs'),
|
|||||||
}
|
}
|
||||||
}, Plugins.libraries[data.id]);
|
}, Plugins.libraries[data.id]);
|
||||||
|
|
||||||
if (method === null) {
|
|
||||||
winston.warn('[plugins/' + id + '] Hook method mismatch: ' + data.hook + ' => ' + data.method);
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the actual method reference to the hookObj
|
// Write the actual method reference to the hookObj
|
||||||
data.method = method;
|
data.method = method;
|
||||||
|
|
||||||
|
register();
|
||||||
|
} else if (typeof data.method === 'function') {
|
||||||
|
register();
|
||||||
|
} else {
|
||||||
|
winston.warn('[plugins/' + id + '] Hook method mismatch: ' + data.hook + ' => ' + data.method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function register() {
|
||||||
Plugins.loadedHooks[data.hook] = Plugins.loadedHooks[data.hook] || [];
|
Plugins.loadedHooks[data.hook] = Plugins.loadedHooks[data.hook] || [];
|
||||||
Plugins.loadedHooks[data.hook].push(data);
|
Plugins.loadedHooks[data.hook].push(data);
|
||||||
|
|
||||||
@@ -680,4 +686,5 @@ var fs = require('fs'),
|
|||||||
callback(err, plugins);
|
callback(err, plugins);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
}(exports));
|
}(exports));
|
||||||
|
|||||||
Reference in New Issue
Block a user