Worked on content type condition
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { ManifestWorkspaceView } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const workspace: ManifestWorkspaceView = {
|
||||
type: 'workspaceView',
|
||||
alias: 'Example.WorkspaceView.EntityContentTypeCondition',
|
||||
name: "Example Workspace View With Entity Content Type Condition",
|
||||
element : () => import('./workspace-view.element.js'),
|
||||
meta: {
|
||||
icon : 'icon-bus',
|
||||
label : 'Conditional',
|
||||
pathname : 'conditional'
|
||||
},
|
||||
conditions : [
|
||||
{
|
||||
alias : 'Umb.Condition.EntityContentType',
|
||||
oneOf : ['29643452-cff9-47f2-98cd-7de4b6807681','media-type-1-id']
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export const manifests = [
|
||||
workspace
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
import { css, html } from 'lit';
|
||||
import { customElement } from 'lit/decorators.js';
|
||||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
|
||||
|
||||
@customElement('umb-example-entity-content-type-condition')
|
||||
export class UmbWorkspaceViewElement extends UmbLitElement {
|
||||
render() {
|
||||
return html`<p>This is a conditional element that is only shown in workspaces based on it's entities content type.</p>`;
|
||||
}
|
||||
|
||||
static styles = [css``];
|
||||
}
|
||||
|
||||
export default UmbWorkspaceViewElement
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'umb-example-entity-content-type-condition': UmbWorkspaceViewElement;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import type { SectionAliasConditionConfig } from './section-alias.condition.js';
|
||||
import type { SwitchConditionConfig } from './switch.condition.js';
|
||||
import type {
|
||||
WorkspaceAliasConditionConfig,
|
||||
WorkspaceEntityContentTypeConditionConfig,
|
||||
WorkspaceEntityTypeConditionConfig,
|
||||
} from '@umbraco-cms/backoffice/workspace';
|
||||
import type { UmbConditionConfigBase } from '@umbraco-cms/backoffice/extension-api';
|
||||
@@ -22,7 +23,7 @@ export type BlockWorkspaceHasSettingsConditionConfig =
|
||||
export type BlockEntryShowContentEditConditionConfig =
|
||||
UmbConditionConfigBase<'Umb.Condition.BlockEntryShowContentEdit'>;
|
||||
|
||||
export type ConditionTypes =
|
||||
export type ConditionTypes =
|
||||
| BlockEntryShowContentEditConditionConfig
|
||||
| BlockWorkspaceHasSettingsConditionConfig
|
||||
| CollectionAliasConditionConfig
|
||||
@@ -33,4 +34,5 @@ export type ConditionTypes =
|
||||
| UmbSectionUserPermissionConditionConfig
|
||||
| WorkspaceAliasConditionConfig
|
||||
| WorkspaceEntityTypeConditionConfig
|
||||
| UmbConditionConfigBase;
|
||||
| UmbConditionConfigBase
|
||||
| WorkspaceEntityContentTypeConditionConfig;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export type { WorkspaceAliasConditionConfig } from './workspace-alias.condition.js';
|
||||
export type { WorkspaceEntityTypeConditionConfig } from './workspace-entity-type.condition.js';
|
||||
export type { WorkspaceHasCollectionConditionConfig } from './workspace-has-collection.condition.js';
|
||||
export type { WorkspaceEntityContentTypeConditionConfig } from './workspace-entity-content-type.condition.js';
|
||||
@@ -1,10 +1,12 @@
|
||||
import { manifest as workspaceAliasCondition } from './workspace-alias.condition.js';
|
||||
import { manifest as workspaceEntityTypeCondition } from './workspace-entity-type.condition.js';
|
||||
import { manifest as workspaceHasCollectionCondition } from './workspace-has-collection.condition.js';
|
||||
import { manifest as workspaceEntityContentTypeCondition } from './workspace-entity-content-type.condition.js';
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const manifests: Array<ManifestTypes> = [
|
||||
workspaceAliasCondition,
|
||||
workspaceEntityTypeCondition,
|
||||
workspaceHasCollectionCondition,
|
||||
workspaceEntityContentTypeCondition
|
||||
];
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { UmbConditionBase } from '../../extension-registry/conditions/condition-base.controller.js';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import type {
|
||||
ManifestCondition,
|
||||
UmbConditionConfigBase,
|
||||
UmbConditionControllerArguments,
|
||||
UmbExtensionCondition,
|
||||
} from '@umbraco-cms/backoffice/extension-api';
|
||||
import { UMB_ENTITY_WITH_CONTENT_TYPE_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/workspace';
|
||||
|
||||
/**
|
||||
* Condition to apply extension based on a entities content type unique
|
||||
*/
|
||||
export class UmbWorkspaceContentTypeCondition extends UmbConditionBase<WorkspaceEntityContentTypeConditionConfig> implements UmbExtensionCondition {
|
||||
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<WorkspaceEntityContentTypeConditionConfig>) {
|
||||
super(host, args);
|
||||
|
||||
let permissionCheck: ((contentTypeUnique: string) => boolean) | undefined = undefined;
|
||||
if (this.config.match) {
|
||||
permissionCheck = (contentTypeUnique: string) => contentTypeUnique === this.config.match;
|
||||
} else if (this.config.oneOf) {
|
||||
permissionCheck = (contentTypeUnique: string) => this.config.oneOf!.indexOf(contentTypeUnique) !== -1;
|
||||
}
|
||||
|
||||
if (permissionCheck !== undefined) {
|
||||
|
||||
this.consumeContext(UMB_ENTITY_WITH_CONTENT_TYPE_WORKSPACE_CONTEXT, (context) => {
|
||||
|
||||
this.observe(context.contentTypeUnique,(contentTypeUnique)=> {
|
||||
this.permitted = contentTypeUnique ? permissionCheck(contentTypeUnique) : false;
|
||||
},
|
||||
'workspaceContentTypeUniqueConditionObserver');
|
||||
});
|
||||
|
||||
} else {
|
||||
throw new Error(
|
||||
'Condition `Umb.Condition.EntityContentType` could not be initialized properly. Either "match" or "oneOf" must be defined',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type WorkspaceEntityContentTypeConditionConfig = UmbConditionConfigBase<'Umb.Condition.EntityContentType'> & {
|
||||
/**
|
||||
* Define the unique content type key where this extension should be available in
|
||||
*
|
||||
* @example
|
||||
* "a1eb4175-3ec1-40ea-8dda-083df6648973"
|
||||
*/
|
||||
match?: string;
|
||||
/**
|
||||
* Define one or more content type keys that this extension should be available in
|
||||
*
|
||||
* @example
|
||||
* ["a1eb4175-3ec1-40ea-8dda-083df6648973", "2ac00e5d-8763-42d9-a38c-adaaee02cfae"]
|
||||
*/
|
||||
oneOf?: Array<string>;
|
||||
};
|
||||
|
||||
export const manifest: ManifestCondition = {
|
||||
type: 'condition',
|
||||
name: 'Workspace Entity Content Type Condition',
|
||||
alias: 'Umb.Condition.EntityContentType',
|
||||
api: UmbWorkspaceContentTypeCondition,
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { UmbWorkspaceContext } from './workspace-context.interface.js';
|
||||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
import type { UmbEntityWithContentTypeWorkspaceContext } from '@umbraco-cms/backoffice/workspace';
|
||||
|
||||
export const UMB_ENTITY_WITH_CONTENT_TYPE_WORKSPACE_CONTEXT = new UmbContextToken<UmbWorkspaceContext, UmbEntityWithContentTypeWorkspaceContext>(
|
||||
'UmbWorkspaceContext',
|
||||
undefined,
|
||||
(context): context is UmbEntityWithContentTypeWorkspaceContext => (context as any).contentTypeUnique !== undefined,
|
||||
);
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { UmbWorkspaceContext } from './workspace-context.interface.js';
|
||||
import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
|
||||
export interface UmbEntityWithContentTypeWorkspaceContext extends UmbWorkspaceContext {
|
||||
|
||||
/**
|
||||
* Unique identifier for the entities content type
|
||||
*/
|
||||
readonly contentTypeUnique : Observable<string | undefined>;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ export * from './routable-workspace.context-token.js';
|
||||
export * from './submittable-workspace.context-token.js';
|
||||
export * from './variant-workspace.context-token.js';
|
||||
export * from './workspace.context-token.js';
|
||||
export * from './entity-with-content-type-workspace-context-token.js';
|
||||
export type * from './collection-workspace-context.interface.js';
|
||||
export type * from './entity-workspace-context.interface.js';
|
||||
export type * from './invariant-dataset-workspace-context.interface.js';
|
||||
@@ -15,3 +16,4 @@ export type * from './routable-workspace-context.interface.js';
|
||||
export type * from './submittable-workspace-context.interface.js';
|
||||
export type * from './variant-dataset-workspace-context.interface.js';
|
||||
export type * from './workspace-context.interface.js';
|
||||
export type * from './entity-with-content-type-workspace-context.interface.js';
|
||||
@@ -69,7 +69,8 @@ export class UmbDocumentWorkspaceContext
|
||||
implements
|
||||
UmbContentWorkspaceContext<UmbDocumentTypeDetailModel, UmbDocumentVariantModel>,
|
||||
UmbPublishableWorkspaceContext,
|
||||
UmbCollectionWorkspaceContext<UmbDocumentTypeDetailModel>
|
||||
UmbCollectionWorkspaceContext<UmbDocumentTypeDetailModel>,
|
||||
UmbEntityWithContentTypeWorkspaceContext
|
||||
{
|
||||
public readonly IS_CONTENT_WORKSPACE_CONTEXT = true as const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user