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]) {
|
if (this.container.cache[resolverName]) {
|
||||||
console.warn(`"${resolverName}" was already cached in the container. Changes won't be applied.`);
|
console.warn(`"${resolverName}" was already cached in the container. Changes won't be applied.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const klass = this.container.factoryFor(resolverName);
|
const klass = this.container.factoryFor(resolverName);
|
||||||
|
if (!klass) {
|
||||||
|
if (!opts.ignoreMissing) {
|
||||||
|
console.warn(`"${resolverName}" was not found by modifyClass`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
klass.class.reopen(changes);
|
klass.class.reopen(changes);
|
||||||
return klass;
|
return klass;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue