Skip to content

Commit 8dd2bbd

Browse files
committed
add condition to check for content properties
1 parent 732d9af commit 8dd2bbd

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const UMB_CONTENT_HAS_PROPERTIES_WORKSPACE_CONDITION = 'Umb.Condition.Workspace.ContentHasProperties';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { ManifestCondition } from '@umbraco-cms/backoffice/extension-api';
2+
3+
export const manifest: ManifestCondition = {
4+
type: 'condition',
5+
name: 'Content has properties Workspace Condition',
6+
alias: 'Umb.Condition.Workspace.ContentHasProperties',
7+
api: () => import('./content-has-properties.condition.js'),
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
2+
import type {
3+
UmbConditionConfigBase,
4+
UmbConditionControllerArguments,
5+
UmbExtensionCondition,
6+
} from '@umbraco-cms/backoffice/extension-api';
7+
import { UMB_CONTENT_WORKSPACE_CONTEXT } from '../../../../content-workspace.context-token.js';
8+
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry';
9+
import type { UmbContentTypeModel } from '@umbraco-cms/backoffice/content-type';
10+
import { UmbContentTypePropertyStructureHelper } from '@umbraco-cms/backoffice/content-type';
11+
12+
export class UmbContentHasPropertiesWorkspaceCondition
13+
extends UmbConditionBase<UmbConditionConfigBase>
14+
implements UmbExtensionCondition
15+
{
16+
#propertyStructureHelper = new UmbContentTypePropertyStructureHelper<UmbContentTypeModel>(this);
17+
18+
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<UmbConditionConfigBase>) {
19+
super(host, args);
20+
21+
this.consumeContext(UMB_CONTENT_WORKSPACE_CONTEXT, (context) => {
22+
this.observe(
23+
context.structure.contentTypes,
24+
(contentTypes) => {
25+
const hasProperties = contentTypes.some((contentType) => contentType.properties.length > 0);
26+
this.permitted = hasProperties;
27+
},
28+
'contentTypesObserver',
29+
);
30+
});
31+
}
32+
}
33+
34+
export { UmbContentHasPropertiesWorkspaceCondition as api };
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './constants.js';

0 commit comments

Comments
 (0)