mirror of
https://github.com/flarum/framework.git
synced 2025-04-19 18:31:04 +08:00
fix: admin extender execution order
This commit is contained in:
parent
dbaf77d0f0
commit
da4913902e
@ -129,12 +129,14 @@ export default class AdminApplication extends Application {
|
||||
this.route = (Object.getPrototypeOf(Object.getPrototypeOf(this)) as Application).route.bind(this);
|
||||
}
|
||||
|
||||
protected beforeMount(): void {
|
||||
protected runBeforeMount(): void {
|
||||
BasicsPage.register();
|
||||
AppearancePage.register();
|
||||
MailPage.register();
|
||||
AdvancedPage.register();
|
||||
PermissionsPage.register();
|
||||
|
||||
super.runBeforeMount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -286,6 +286,8 @@ export default class Application {
|
||||
|
||||
private handledErrors: { extension: null | string; errorId: string; error: any }[] = [];
|
||||
|
||||
private beforeMounts: (() => void)[] = [];
|
||||
|
||||
public load(payload: Application['data']) {
|
||||
this.data = payload;
|
||||
this.translator.setLocale(payload.locale);
|
||||
@ -326,7 +328,7 @@ export default class Application {
|
||||
|
||||
this.session = new Session(this.store.getById<User>('users', String(this.data.session.userId)) ?? null, this.data.session.csrfToken);
|
||||
|
||||
this.beforeMount();
|
||||
this.runBeforeMount();
|
||||
|
||||
this.mount();
|
||||
|
||||
@ -335,8 +337,13 @@ export default class Application {
|
||||
caughtInitializationErrors.forEach((handler) => handler());
|
||||
}
|
||||
|
||||
protected beforeMount(): void {
|
||||
// ...
|
||||
public beforeMount(callback: () => void) {
|
||||
this.beforeMounts.push(callback);
|
||||
}
|
||||
|
||||
protected runBeforeMount(): void {
|
||||
this.beforeMounts.forEach((callback) => callback());
|
||||
this.beforeMounts = [];
|
||||
}
|
||||
|
||||
public bootExtensions(extensions: Record<string, { extend?: IExtender[] }>) {
|
||||
|
@ -124,62 +124,64 @@ export default class Admin implements IExtender<AdminApplication> {
|
||||
}
|
||||
|
||||
extend(app: AdminApplication, extension: IExtensionModule) {
|
||||
app.registry.for(this.context || extension.name);
|
||||
app.beforeMount(() => {
|
||||
app.registry.for(this.context || extension.name);
|
||||
|
||||
this.settings.forEach(({ setting, customSetting, priority }) => {
|
||||
const settingConfig = setting ? setting() : customSetting!;
|
||||
this.settings.forEach(({ setting, customSetting, priority }) => {
|
||||
const settingConfig = setting ? setting() : customSetting!;
|
||||
|
||||
if (settingConfig) {
|
||||
app.registry.registerSetting(settingConfig, priority);
|
||||
if (settingConfig) {
|
||||
app.registry.registerSetting(settingConfig, priority);
|
||||
}
|
||||
});
|
||||
|
||||
this.settingReplacements.forEach(({ setting, replacement }) => {
|
||||
app.registry.setSetting(setting, replacement);
|
||||
});
|
||||
|
||||
this.settingPriorityChanges.forEach(({ setting, priority }) => {
|
||||
app.registry.setSettingPriority(setting, priority);
|
||||
});
|
||||
|
||||
this.settingRemovals.forEach((setting) => {
|
||||
app.registry.removeSetting(setting);
|
||||
});
|
||||
|
||||
this.permissions.forEach(({ permission, type, priority }) => {
|
||||
const permissionConfig = permission();
|
||||
|
||||
if (permissionConfig) {
|
||||
app.registry.registerPermission(permissionConfig, type, priority);
|
||||
}
|
||||
});
|
||||
|
||||
this.permissionsReplacements.forEach(({ permission, type, replacement }) => {
|
||||
app.registry.setPermission(permission, replacement, type);
|
||||
});
|
||||
|
||||
this.permissionsPriorityChanges.forEach(({ permission, type, priority }) => {
|
||||
app.registry.setPermissionPriority(permission, type, priority);
|
||||
});
|
||||
|
||||
this.permissionsRemovals.forEach(({ permission, type }) => {
|
||||
app.registry.removePermission(permission, type);
|
||||
});
|
||||
|
||||
if (this.customPage) {
|
||||
app.registry.registerPage(this.customPage);
|
||||
}
|
||||
});
|
||||
|
||||
this.settingReplacements.forEach(({ setting, replacement }) => {
|
||||
app.registry.setSetting(setting, replacement);
|
||||
});
|
||||
app.generalIndex.for(extension.name);
|
||||
|
||||
this.settingPriorityChanges.forEach(({ setting, priority }) => {
|
||||
app.registry.setSettingPriority(setting, priority);
|
||||
});
|
||||
Object.keys(this.generalIndexes).forEach((key) => {
|
||||
if (key !== 'settings' && key !== 'permissions') return;
|
||||
|
||||
this.settingRemovals.forEach((setting) => {
|
||||
app.registry.removeSetting(setting);
|
||||
});
|
||||
const callback = this.generalIndexes[key];
|
||||
|
||||
this.permissions.forEach(({ permission, type, priority }) => {
|
||||
const permissionConfig = permission();
|
||||
|
||||
if (permissionConfig) {
|
||||
app.registry.registerPermission(permissionConfig, type, priority);
|
||||
}
|
||||
});
|
||||
|
||||
this.permissionsReplacements.forEach(({ permission, type, replacement }) => {
|
||||
app.registry.setPermission(permission, replacement, type);
|
||||
});
|
||||
|
||||
this.permissionsPriorityChanges.forEach(({ permission, type, priority }) => {
|
||||
app.registry.setPermissionPriority(permission, type, priority);
|
||||
});
|
||||
|
||||
this.permissionsRemovals.forEach(({ permission, type }) => {
|
||||
app.registry.removePermission(permission, type);
|
||||
});
|
||||
|
||||
if (this.customPage) {
|
||||
app.registry.registerPage(this.customPage);
|
||||
}
|
||||
|
||||
app.generalIndex.for(extension.name);
|
||||
|
||||
Object.keys(this.generalIndexes).forEach((key) => {
|
||||
if (key !== 'settings' && key !== 'permissions') return;
|
||||
|
||||
const callback = this.generalIndexes[key];
|
||||
|
||||
if (callback) {
|
||||
app.generalIndex.add(key, callback());
|
||||
}
|
||||
if (callback) {
|
||||
app.generalIndex.add(key, callback());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user