mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 05:43:16 +08:00
Allow modifyClass
to operate on optional classes.
This is useful if you want to modify an admin class that might not be present for regular users.
This commit is contained in:
parent
09ed2ed749
commit
e809996c2a
|
@ -54,12 +54,21 @@ class PluginApi {
|
|||
* });
|
||||
* ```
|
||||
**/
|
||||
modifyClass(resolverName, changes) {
|
||||
modifyClass(resolverName, changes, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
if (this.container.cache[resolverName]) {
|
||||
console.warn(`"${resolverName}" was already cached in the container. Changes won't be applied.`);
|
||||
}
|
||||
|
||||
const klass = this.container.factoryFor(resolverName);
|
||||
if (!klass) {
|
||||
if (!opts.ignoreMissing) {
|
||||
console.warn(`"${resolverName}" was not found by modifyClass`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
klass.class.reopen(changes);
|
||||
return klass;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user