add entity context

This commit is contained in:
Mads Rasmussen
2024-04-05 18:32:20 +02:00
parent 9a36c13c04
commit c4d08b92b1
2 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
import type { UmbEntityContext } from './entity.context.js';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
export const UMB_ENTITY_CONTEXT = new UmbContextToken<UmbEntityContext>('UmbEntityContext');

View File

@@ -0,0 +1,42 @@
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbStringState } from '@umbraco-cms/backoffice/observable-api';
/**
* UmbEntityContext
* @export
* @class UmbEntityContext
* @extends {UmbContextBase<UmbEntityContext>}
*/
export class UmbEntityContext extends UmbContextBase<UmbEntityContext> {
#entityType = new UmbStringState<string | undefined>(undefined);
public readonly entityType = this.#entityType.asObservable();
#unique = new UmbStringState<string | null | undefined>(undefined);
public readonly unique = this.#unique.asObservable();
/**
* Creates an instance of UmbEntityContext.
* @param {UmbControllerHost} host
* @memberof UmbEntityContext
*/
constructor(host: UmbControllerHost) {
super(host, 'entity');
}
setEntityType(entityType: string | undefined) {
this.#entityType.setValue(entityType);
}
getEntityType() {
return this.#entityType.getValue();
}
setUnique(unique: string | null | undefined) {
this.#unique.setValue(unique);
}
getUnique() {
return this.#unique.getValue();
}
}