Workspace entity condition
# package-development
p
Also, is it possible to expose the ID of the current entity in a workspace entity condition? I have a workspace view that is only used on specific content items
w
Hiya think you will need to create your own custom condition. As far as I know there is not one shipped by Umbraco that covers that scenario.
p
I do have that yeah, but I don't know how to access the current ID 😅 . There isn't something like the old editorState right?
w
Most likely want the workspace context and then the Unique
Which is the ID/Guid
n
We do not ship one to match on the unique/GUID/ID. In general that is not ideal, but yes if you like to do something very specific you can. And such Condition would be very close to the Workspace Entity Type Condition. So I just made a few changes to it and here you have a Workspace Entity Unique Condition (well, you need to clone some types as well, But I hope you get the concept, otherwise let me know):
Copy code
import { UMB_ENTITY_WORKSPACE_CONTEXT } from '../contexts/index.js';
import type { WorkspaceEntityTypeConditionConfig } from './types.js';
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry';
import type {
    ManifestCondition,
    UmbConditionControllerArguments,
    UmbExtensionCondition,
} from '@umbraco-cms/backoffice/extension-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';

export class UmbWorkspaceEntityUniqueCondition
    extends UmbConditionBase<WorkspaceEntityTypeConditionConfig>
    implements UmbExtensionCondition
{
    constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<WorkspaceEntityTypeConditionConfig>) {
        super(host, args);
        this.consumeContext(UMB_ENTITY_WORKSPACE_CONTEXT, (context) => {
            this.permitted = context.getUnique() === this.config.match;
        });
    }
}

export const manifest: ManifestCondition = {
    type: 'condition',
    name: 'Workspace Entity Type Condition',
    alias: 'Umb.Condition.WorkspaceEntityUnique',
    api: UmbWorkspaceEntityUniqueCondition,
};
p
Perfect! I had most of this code, I was just missing the correct permitted check (with the context). Thank you!
7 Views