add readonly state manager to block entry context

This commit is contained in:
Mads Rasmussen
2024-10-09 13:42:31 +02:00
parent 89e7ed9a2f
commit 60b8d7e320

View File

@@ -13,7 +13,7 @@ import {
mergeObservables,
observeMultiple,
} from '@umbraco-cms/backoffice/observable-api';
import { encodeFilePath } from '@umbraco-cms/backoffice/utils';
import { encodeFilePath, UmbReadOnlyVariantStateManager } from '@umbraco-cms/backoffice/utils';
import { umbConfirmModal } from '@umbraco-cms/backoffice/modal';
import type {
UmbContentTypeModel,
@@ -50,6 +50,8 @@ export abstract class UmbBlockEntryContext<
#hasExpose = new UmbBooleanState(undefined);
hasExpose = this.#hasExpose.asObservable();
public readonly readOnlyState = new UmbReadOnlyVariantStateManager(this);
// Workspace alike methods, to enables editing of data without the need of a workspace (Custom views and block grid inline editing mode for example).
getEntityType() {
return 'block';
@@ -409,6 +411,7 @@ export abstract class UmbBlockEntryContext<
this.#observeBlockType();
this.#observeContentData();
this.#observeSettingsData();
this.#observeReadOnlyState();
}
abstract _gotManager(): void;
@@ -491,6 +494,31 @@ export abstract class UmbBlockEntryContext<
);
}
#observeReadOnlyState() {
if (!this._manager) return;
this.observe(
observeMultiple([this._manager.readOnlyState.isReadOnly, this._manager.variantId]),
([isReadOnly, variantId]) => {
const unique = 'UMB_BLOCK_MANAGER_CONTEXT';
if (variantId === undefined) return;
if (isReadOnly) {
const state = {
unique,
variantId,
message: '',
};
this.readOnlyState?.addState(state);
} else {
this.readOnlyState?.removeState(unique);
}
},
'observeIsReadOnly',
);
}
#getContentStructure() {
if (!this._manager) return;