add global context to load in the document configuration
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
|
||||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api';
|
||||
import {
|
||||
DocumentResource,
|
||||
type DocumentConfigurationResponseModel,
|
||||
} from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
|
||||
/**
|
||||
* A context for fetching and caching the document configuration.
|
||||
*/
|
||||
export class UmbDocumentConfigurationContext extends UmbControllerBase implements UmbApi {
|
||||
static DocumentConfiguration: Promise<DocumentConfigurationResponseModel | null>;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
this.provideContext(UMB_DOCUMENT_CONFIGURATION_CONTEXT, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the document configuration from the server, or return the cached configuration if it has already been fetched.
|
||||
* @returns A promise that resolves to the document configuration, or null if the configuration could not be fetched.
|
||||
*/
|
||||
getDocumentConfiguration(): Promise<DocumentConfigurationResponseModel | null> {
|
||||
debugger;
|
||||
return (UmbDocumentConfigurationContext.DocumentConfiguration ??= this.fetchDocumentConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the document configuration from the server.
|
||||
* @returns A promise that resolves to the document configuration, or null if the configuration could not be fetched.
|
||||
*/
|
||||
async fetchDocumentConfiguration() {
|
||||
const { data } = await tryExecuteAndNotify(this, DocumentResource.getDocumentConfiguration());
|
||||
|
||||
return data ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
export default UmbDocumentConfigurationContext;
|
||||
|
||||
export const UMB_DOCUMENT_CONFIGURATION_CONTEXT = new UmbContextToken<UmbDocumentConfigurationContext>(
|
||||
'UmbDocumentConfigurationContext',
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
export * from './document-configuration.context.js';
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { ManifestGlobalContext } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const manifests: Array<ManifestGlobalContext> = [
|
||||
{
|
||||
type: 'globalContext',
|
||||
alias: 'Umb.GlobalContext.DocumentConfiguration',
|
||||
name: 'Document Configuration Context',
|
||||
js: () => import('./document-configuration.context.js'),
|
||||
},
|
||||
];
|
||||
@@ -9,6 +9,7 @@ export * from './components/index.js';
|
||||
export * from './entity.js';
|
||||
export * from './entity-actions/index.js';
|
||||
export * from './modals/index.js';
|
||||
export * from './global-contexts/index.js';
|
||||
|
||||
export * from './tree/index.js';
|
||||
export { UMB_CONTENT_MENU_ALIAS } from './menu.manifests.js';
|
||||
|
||||
@@ -11,6 +11,7 @@ import { manifests as modalManifests } from './modals/manifests.js';
|
||||
import { manifests as treeManifests } from './tree/manifests.js';
|
||||
import { manifests as userPermissionManifests } from './user-permissions/manifests.js';
|
||||
import { manifests as workspaceManifests } from './workspace/manifests.js';
|
||||
import { manifests as globalContextManifests } from './global-contexts/manifests.js';
|
||||
|
||||
export const manifests = [
|
||||
...breadcrumbManifests,
|
||||
@@ -26,4 +27,5 @@ export const manifests = [
|
||||
...treeManifests,
|
||||
...userPermissionManifests,
|
||||
...workspaceManifests,
|
||||
...globalContextManifests,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user